Why doesn't the free space on the source partition change during "mv"?

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?

Asked By: Tim

||

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.

Answered By: cuonglm

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

Answered By: hildred
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.