13

I am running mv to move a directory (which contains many files) from one partition to another. While mv is moving individual files in the directory one by one, I notice that the free space size of the source partition doesn't change, while the free space size of the destination partition is decreasing.

Why is it working that way, instead of the sum of the free space sizes of the source and destination partitions stay the same?

16

As POSIX define, mv will duplicate source file to the destination path, and if nothing goes wrong, the source file shall be removed:

  1. The file hierarchy rooted in source_file shall be duplicated as a file hierarchy rooted in the destination path

  2. The file hierarchy rooted in source_file shall be removed. If this fails for any reason, mv shall write a diagnostic message to the standard error, do nothing more with the current source_file, and go on to any remaining source_files.

If you move on the same file system you only move the entry from one location in the file system to another one.

It guaranteed that you will not lose the source file if errors occurs during moving process.

16

It is being conservative and not deleting files until the copy succeeds. This makes it easier to recover if something goes wrong.

  • but the dir has many files – Tim Feb 14 '15 at 4:22
  • 7
    @Tim: It doesn't start removing source files until all of the files have been duplicated on the destination volume. If you need the files to be moved one at a time, so that there is never more "extra" space used than that of the largest file, you need to build a loop to do this. – Warren Young Feb 14 '15 at 4:36
  • 4
    Have you ever done a move in MS-Windows, and about half way through the move, something goes wrong. Both source and destination are a mess, and you are left to fix it. If you are not a supper geek, then you probably just delete both, and learn not to do it again. – ctrl-alt-delor Feb 14 '15 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.