Why `df` and `du` Don't Match

Linux users are often surprised that the two command line tools to report disk utilisation give different results for the amount of space used. However, there are very good reasons for this disparity because the two tools work in completely different ways. The results should never be expected to match!

df reads statistics about available blocks from the filesystem driver through the statfs() system call. It subtracts the number of available blocks from the total to deduce the space used.

du reads the number of blocks used to store each file and directory using the stat() system call. It can sum these for every entry in the filesystem to deduce the space used.

Effectively df asks about the filesystem as a whole, and du asks about each entry individually.

The reasons for the disparity are thus:

It should also be noted that the space df reports as free may not be available to store files. On ReiserFS, filesystem internals grow as the numbers of files stored grows. On Ext2/3, some number of blocks are reserved for root processes to use.

WhydfAndduDontMatch (last edited 2007-12-28 22:50:00 by 217)