14

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?

Mat
  • 52,586
Tim
  • 101,790

2 Answers2

17

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.

cuonglm
  • 153,898
16

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

hildred
  • 5,829
  • 3
  • 31
  • 43
  • but the dir has many files – Tim Feb 14 '15 at 04: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 04: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