This question already has an answer here:

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?

marked as duplicate by Gilles linux Oct 13 '14 at 21:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    You should us '-a' too for archive mode. – geedoubleya Oct 13 '14 at 10:38
  • cp -ar still gives different outputs with du. – BowPark Oct 13 '14 at 11:03

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.


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.

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