du and df discrepancy

Dag-Erling Smørgrav des at des.no
Wed Oct 17 04:49:31 PDT 2007


Bill Vermillion <bv at wjv.com> writes:
> I've seen it many times in my XX years of Unix work.
>
> du - shows the amount of blocks used by the system
> df - shows the amunt of space it thinks is being used.
>
> The latter will compute the length of sparse files so df will show
> less free space than du.  Sparse file will have blocks of no data in
> them.  These are typically created by database programs.

Utterly wrong.

df will show the amount of space used in the file system, including
space used by files that have no directory entry (e.g. temporary files
which the application unlinks immediately after opening)

du will show the amount of space used by the files it is able to find by
traversing the directories specified on the command line.

Both will DTRT for sparse files.

Note that when running 'du *' in the root of a file system, the shell
will most likely not include directories and files whose names begin
with a dot in its expansion of '*'.

DES
-- 
Dag-Erling Smørgrav - des at des.no


More information about the freebsd-fs mailing list