Under following conditions-
mv
within the same HDD partitionmv
to a different partition in the same HDDmv
to a different device (e.g. USB HDD)
Is the complete file moved or is it a very small change like some pointer reassignment ?
Under following conditions-
mv
within the same HDD partitionmv
to a different partition in the same HDDmv
to a different device (e.g. USB HDD)Is the complete file moved or is it a very small change like some pointer reassignment ?
It's up to each filesystem how to handle a move within the filesystem (also known as renaming a file), but filesystems pretty much universally handle it by updating directory entries without moving the inode or file contents.
A move between filesystems (it doesn't matter if it's on the same physical medium or not) is handled as a file copy followed by a delete. This is in fact exactly what the mv
command does. Obviously that means that the destination filesystem has to make a new copy of the file.
mv
is interrupted before deletion, does the file remain intact at the source ?
– user13107
Sep 13 '12 at 17:54
mv
is interrupted. Depending on whether or not mv
is given a chance to clean up after itself when it gets interrupted you may find a partially copied file at the destination too!
– Celada
Sep 13 '12 at 17:59
man mv
says:
As the rename(2) call does not work across file systems, mv uses cp(1) and rm(1) to
accomplish the move. The effect is equivalent to:
rm -f destination_path && \
cp -pRP source_file destination && \
rm -rf source_file
mv
procedure in different ways. – Paweł Rumian Sep 13 '12 at 17:50