Different sizes after copy

10,068

Solution 1

Additional blocks are allocated, as needed, to directories as files and sub-directories are added. Subsequent removal of these files and sub-directories do not result in disposal of the now empty/reusable allocation. Hence it is very common for the destination directory of a copy operation to be slightly smaller than its source.

You can diff recursively the source and destination directories to confirm everything has been copied if you want a warm-fuzzy confirmation.

As an aside, rsync is also ideal for replicating structures:

rsync -avz /source-directory/ /backup-directory

The trailing slash on the source-directory means that the source-directory name is not included in the backup-directory as its first sub-directory.

The -avz options tell rsync to copy in archive mode to preserve permissions, ownerships, symbolic links, etc., using compresssion during the transfer process and reporting actions verbosely.

Solution 2

Different filesystems may have differing overhead while allocating space for files. Also how directory entries are stored may differ. You unfortunately don't tell what the different outputs are.

Share:
10,068

Related videos on Youtube

BowPark
Author by

BowPark

Updated on September 18, 2022

Comments

  • BowPark
    BowPark almost 2 years

    I would like to copy for backup porposes a Linux user home directory with several GBs of data and the usual configuration files. The source directory and the backup directory should exactly have the same contents. The OS is Lubuntu.

    The directory contains hidden files and subdirectories. After some googling I found that

    cp -r /source-directory /backup-directory
    

    was the appropriate command.

    The source directory filesystem is ext4 and the destination directory is NTFS. After the copy, diff -qr /source-directory /backup-directory gives no output (so I suppose no differences). But du, or du -b or du --apparent-size all give always different outputs for the source directory and the backup directory.

    Why? Was the command wrong or is this use of du wrong?

    • Admin
      Admin over 9 years
      You should us '-a' too for archive mode.
    • Admin
      Admin over 9 years
      cp -ar still gives different outputs with du.
  • jave.web
    jave.web over 3 years
    I was recommended this question for sparse file or sparseness - just adding the keywords for others that will CTR+F this page x)