Why do df and du show different output?

10,033

Solution 1

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.

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

Share:
10,033

Related videos on Youtube

Nischay
Author by

Nischay

Updated on September 18, 2022

Comments

  • Nischay
    Nischay over 1 year

    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.

  • jdhildeb
    jdhildeb about 6 years
    Bingo. This was the cause for me.