9

When I execute the command df -h /tmp it says disk utilization is 100%, but when it try du -sh /tmp it says disk utilization is 2%.

I want to know why these commands shows different output, how these two commands work and what is the solution to this problem.

Context: /tmp is installed on it own file system. I am using Ubuntu 12.04 server edition on my VPS account. Due to this problem utilization of /tmp 100% according to df some programs complain about free space in /tmp.

3 Answers 3

11

du reports free space by scanning reachable inodes and calculating their size.

If a file is created, opened, and later deleted while it is still open, the program that opened it will continue to have access to the file, and writes and reads can be performed to that memory location on disk. du does not account for such open files whereas df does.

A simple restart should flush /tmp and solve your problem.

An alternative would be to scan open files and restart or kill the process that did not release the deleted files.

2

Some files on root filesystem can be hidden behind a mount point. Files can be created under the mount point when corresponding device is not mounted, and when device is mounted again, files are not counted by du command. Very probable issue, when there is a big difference between du and df results.

1
  • Bingo. This was the cause for me.
    – jdhildeb
    Feb 27, 2018 at 18:32
-1

Make sure you sudo when running du. For instance, if you run du -hs /*, you won't see the real disk usage unless you add sudo.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .