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.
- 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.