Linux – Understanding the different directory sizes

bashdulinux

When comparing

root@debian:~# du -s /backup/test1/
5605364 /backup/test1/

two directories with du,

root@debian:/etc/init.d# du -s /data/test1/
5605360 /data/test1/

du tells me that there is a small difference in the total size of each directory.

Diff, on the other hand, tells me that both directoies are identical:

root@debian:/etc/init.d# diff -r /data/test1/ /backup/test1/

What is the reason?

Best Answer

du reports the "disk usage" of the files, not the exact byte count each files contains. the man page of du even says:

du - estimate file space usage

it is entirely possible that the same set of files use different amout of disk space. this is because of the intricacies of the file system. for more information about the disk usage on the filesystem read the following question and answers: https://superuser.com/questions/218395/about-file-size-and-disk-usage-in-ext3.

diff compares the contents of the files. diff does not care about how many bytes a file actually use on the file system. it only cares about the bytes in the files.

if you want du to report the exact byte count for each file you can use --apparent-size.

Related Topic