LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Result from 'df' does not add up (https://www.linuxquestions.org/questions/linux-general-1/result-from-df-does-not-add-up-509236/)

matsamuel 12-10-2006 07:41 PM

Result from 'df' does not add up
 
So I'm trying out this 'df' command in Linux and the numbers don't quite add up although I'm sure there's a reasonable explanation for this. So the 'df' command reports filesystem disk space usage.

Here's an example of the command that I try:

df -h /tmp

And here is the result:

Filesystem Size Used Avail Use% Mounted on
/dev/sda7 9.7G 33M 9.1G 1% /tmp

So I would have thought that Used + Avail = Size but that does not apply above as it just doesn't add up.

I've tried this with other directories as well, not just /tmp, and the numbers are inconsistent for the other ones I've tried as well.

I'm just hoping some one may be able to explain why the result does not add up? What am I missing here? Any help would be greatly appreciated. Thanks!

Cheers,
Matt

matthewg42 12-10-2006 08:25 PM

There are two usual reasons for this:

1. Confusing between Megabytes and Mebibytes, Gigabytes and Gibibtes etc. So many programs get it wrong, it's hardly surprising people make small errors in the calculation. Can you show your working so we can check it.

2. Linux doesn't actually delete files until the last link to a file is "unlinked" (the system call which deleted files). Each file has a link count. When the file exists in a directory listing, that counts as one link. If you make a hard link with the ln command from another file name, the link count is incremented. Also, when a program opens a file, the link count is incremented. The file is only deleted when all links (including those from running program who have the file open) have been unlinked.

This means that if programs have files open, but the file has been removed from a directory listing, the space will not be freed up until the last program with the file open has closed the file handle.

You can check for this using the lsof command. As root (or with sudo if it is configured for your user) run this command:
Code:

lsof |fgrep -e DEL -e '(deleted)'


All times are GMT -5. The time now is 02:05 PM.