Why df and du don’t report the same disk space used….

Sooner or later, you’re bound to come up against this mystery.  Once you understand it, it’s not that much of a mystery – but it does seem quite unusual until you understand it.

The utility df reports disk used and disk free from the disk’s internal information; that is, how many blocks on disk are marked as free, and how many are not.  The utility du, on the other hand, reports how much space the selected files take up on disk.

Consider:

  • df reports blocks marked as used.
  • du reports blocks used by files.

The discreprency comes in based on those two facts: there are blocks marked as used that are not used by files.

How can that be?  Well, the mystery shall be revealed: when a file is deleted, if another process has it open, that file is not marked as free (though it is no longer in the filesystem).  This file remains open by the other process, but is no longer discoverable in the filesystem directory structure – and its disk blocks remain in use.

Now you know.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: