osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Does mv on a FAT filesystem actually rename or does it copy and delete?


On Sat, 3 Feb 2018 11:51:18 +0100, Ralf Mardorf wrote:
>On Sat, 3 Feb 2018 09:50:31 +0000, Chris Green wrote:
>>I want to rename some picture files on a mounted digital camera
>>filesystem.  It is a VFAT filesystem.
>>
>>If I rename one of the files using 'mv <xxxx.yyy>' will the file
>>*actually* be renamed by changing the directory entry only or will
>>mv copy the file to one with the new name and then delete the old
>>one?   
>
>"mv" is atomic, you could verify, if I'm mistaken by using strace. "mv"
>sometimes is used to workaround the non-atomic operation "ln".
>
>However, I suspect you aren't asking if "mv" works atomic.
>"mv <xxxx.yyy>" isn't a complete command. Take a look at the manpage:
>
>http://manpages.ubuntu.com/manpages/xenial/man1/mv.1.html
>
>"SYNOPSIS
>
>       mv [OPTION]... [-T] SOURCE DEST
>       mv [OPTION]... SOURCE... DIRECTORY
>       mv [OPTION]... -t DIRECTORY SOURCE..."
>
>So using your syntax it means
>
>mv </path/from/xxxx.yyy> </path/to/pppp.qqq>
>
>[rocketmouse at archlinux ~]$ cd /tmp/
>[rocketmouse at archlinux tmp]$ mkdir dir_1 dir_2
>[rocketmouse at archlinux tmp]$ ls -hAl dir_1 dir_2
>dir_1:
>total 0
>
>dir_2:
>total 0
>[rocketmouse at archlinux tmp]$ touch dir_1/test
>[rocketmouse at archlinux tmp]$ ls -hAl dir_1 dir_2
>dir_1:
>total 0
>-rw-r--r-- 1 rocketmouse rocketmouse 0 Feb  3 11:46 test
>
>dir_2:
>total 0
>[rocketmouse at archlinux tmp]$ mv -i dir_1/test dir_2/ 
>[rocketmouse at archlinux tmp]$ ls -hAl dir_1 dir_2
>dir_1:
>total 0
>
>dir_2:
>total 0
>-rw-r--r-- 1 rocketmouse rocketmouse 0 Feb  3 11:46 test
>[rocketmouse at archlinux tmp]$ mv -i dir_2 dir_3
>[rocketmouse at archlinux tmp]$ ls -hAl dir_1 dir_2 dir_3
>ls: cannot access 'dir_2': No such file or directory
>dir_1:
>total 0
>
>dir_3:
>total 0
>-rw-r--r-- 1 rocketmouse rocketmouse 0 Feb  3 11:46 test
>[rocketmouse at archlinux tmp]$
>
>To some extent "-i" ensures that you don't overwrite something by
>accident.

Within the same directory, which actually seems to be your question:

[rocketmouse at archlinux ~]$ cd /tmp/dir_3/
[rocketmouse at archlinux dir_3]$ ls -hAl
total 0
-rw-r--r-- 1 rocketmouse rocketmouse 0 Feb  3 11:46 test
[rocketmouse at archlinux dir_3]$ mv -i /tmp/dir_3/test /tmp/dir_3/test_new
[rocketmouse at archlinux dir_3]$ ls -hAl
total 0
-rw-r--r-- 1 rocketmouse rocketmouse 0 Feb  3 11:46 test_new
[rocketmouse at archlinux dir_3]$

IOW it does "rename", since the operation is atomic.