Why df and du Show Different Disk Usage on Linux and How to Fix It
This article explains why the Linux commands df and du often report different disk usage figures, detailing three main causes—reserved space, phantom (deleted) files, and data present before mounting—and provides concrete commands and steps to identify and resolve each discrepancy.
Background
When administering Linux servers you often need to check disk space using df -lh for overall filesystem usage or du -sh [directory] for a specific directory.
Why df and du May Differ
Three common reasons cause the numbers reported by df and du to diverge:
Reserved space – Ext* filesystems keep a percentage of blocks reserved for the super‑user. This space is counted as used by df but not by du. You can view the reserved block count with tune2fs -l [dev_name] | grep "Reserved block count" and change it with tune2fs -m [size] [dev_name].
Phantom (deleted) files – When a file is deleted while a process still holds an open file descriptor, the file’s data blocks remain allocated. du cannot see the file, but df still reports the space as used. Such files can be listed with lsof | grep deleted. Once the owning process exits or is killed, the space is released.
Uncounted files before mounting – If a directory already contains data before it is mounted onto a new device, the existing data is invisible to du on the new mount point, yet the underlying blocks are occupied and therefore counted by df. To expose the hidden data, stop processes using the mount point with fuser -km [directory], unmount it ( umount [directory]), delete the pre‑existing files, and remount ( mount -t [type] [dev] [directory]).
Additional Tips
Always verify that no other reasons apply before concluding a discrepancy. Checking reserved space, looking for deleted‑but‑open files, and ensuring the mount point was empty before mounting usually resolves most mismatches.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
