From: bzaman on
Hi ,

Surprisingly , the du command in my desktop is showing more disk usage
than df . I came across systems where df command shows more disk usage
than du because df includes metadata information about partition and
also considers disk space consumed by files which are removed but not
yet released by some process .

=====
$ sudo du -sh /
13G /
$ sudo df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/md0 9.5G 8.1G 903M 91% /
---
$ sudo df -h /usr/
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 8.6G 4.6G 3.6G 56% /usr
$ sudo du -sh /usr/
5.0G /usr/
======


Can somebody explain why this discrepancy in df and du results .


Thanks in Advance
Badiuzzaman

From: David Brown on
On 29/04/2010 13:17, bzaman wrote:
> Hi ,
>
> Surprisingly , the du command in my desktop is showing more disk usage
> than df . I came across systems where df command shows more disk usage
> than du because df includes metadata information about partition and
> also considers disk space consumed by files which are removed but not
> yet released by some process .
>
> =====
> $ sudo du -sh /
> 13G /
> $ sudo df -h /
> Filesystem Size Used Avail Use% Mounted on
> /dev/md0 9.5G 8.1G 903M 91% /
> ---
> $ sudo df -h /usr/
> Filesystem Size Used Avail Use% Mounted on
> /dev/sda5 8.6G 4.6G 3.6G 56% /usr
> $ sudo du -sh /usr/
> 5.0G /usr/
> ======
>
>
> Can somebody explain why this discrepancy in df and du results .
>

If you've got lots of sparse files, they will show up in the du disk
usage, but not on the df for disk free.

You'd also get discrepancies if you have other file systems mounted
within these trees - they count for du but not for df.
From: Doug Freyburger on
David Brown wrote:
> bzaman wrote:
>
>> Surprisingly , the du command in my desktop is showing more disk usage
>> than df . I came across systems where df command shows more disk usage
>> than du because df includes metadata information about partition and
>> also considers disk space consumed by files which are removed but not
>> yet released by some process .

This is extremely common.

>> Can somebody explain why this discrepancy in df and du results .
>
> If you've got lots of sparse files, they will show up in the du disk
> usage, but not on the df for disk free.
>
> You'd also get discrepancies if you have other file systems mounted
> within these trees - they count for du but not for df.

Listing at handful of reasons and explaining why they happen is a
standard interview question for anyone claiming to be intermediate or
more in skill and knowledge - Understanding inodes is on the SAGE scale
for intermediate.

Additional reasons include use of hard links.
From: bzaman on
On Apr 29, 4:52 pm, David Brown <da...(a)westcontrol.removethisbit.com>
wrote:
> On 29/04/2010 13:17, bzaman wrote:
>
>
>
> > Hi ,
>
> > Surprisingly , the du command in my desktop is showing more disk usage
> > than df . I came across systems where df command shows more disk usage
> > than du because df  includes metadata information about partition and
> > also considers disk space consumed by files which are removed but not
> > yet released by some process .
>
> > =====
> > $ sudo du -sh /
> > 13G        /
> > $ sudo df -h /
> > Filesystem            Size  Used Avail Use% Mounted on
> > /dev/md0              9.5G  8.1G  903M  91% /
> > ---
> > $ sudo df -h /usr/
> > Filesystem            Size  Used Avail Use% Mounted on
> > /dev/sda5             8.6G  4.6G  3.6G  56% /usr
> > $ sudo du -sh /usr/
> > 5.0G       /usr/
> > ======
>
> > Can somebody explain why this discrepancy in df and du results .
>
> If you've got lots of sparse files, they will show up in the du disk
> usage, but not on the df for disk free.
>
> You'd also get discrepancies if you have other file systems mounted
> within these trees - they count for du but not for df.

Thanks for the reply.
Is there any way to identify these sparse files . Should not be an
issue with the mounts as I have rebooted the host and still du is
showing more disk space than df .

Thanks
Zaman
From: Keith Keller on
On 2010-04-29, David Brown <david(a)westcontrol.removethisbit.com> wrote:
> On 29/04/2010 13:17, bzaman wrote:
>>
>> =====
>> $ sudo du -sh /
^^^^^^^^
>> 13G /
>> $ sudo df -h /
>> Filesystem Size Used Avail Use% Mounted on
>> /dev/md0 9.5G 8.1G 903M 91% /
>> ---
>> $ sudo df -h /usr/
>> Filesystem Size Used Avail Use% Mounted on
>> /dev/sda5 8.6G 4.6G 3.6G 56% /usr
>> $ sudo du -sh /usr/
>> 5.0G /usr/
>> ======
>>
>>
>> Can somebody explain why this discrepancy in df and du results .
>
> You'd also get discrepancies if you have other file systems mounted
> within these trees - they count for du but not for df.

In particular, your first du command includes the 5GB on /usr.
Subtracting that away gets you closer to df's reported 8GB used.

There are plenty of ways to detect a sparse file (see google), but I
don't know of a way using find directly to locate them. Of course you
could combine a detect program with find, but that could be slow on a
large filesystem. You might start in directories that often have sparse
files--/var, for example, often has them (though those particular sparse
files you wouldn't want to mess with!).

--keith

--
kkeller-usenet(a)wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information