Why Do df and du Report Different Disk Usage on Linux? Explained
When managing Linux servers, the df and du commands often show mismatched disk usage figures, and this article explains the three main causes—reserved space, phantom files, and uncounted data—along with how to identify and resolve each discrepancy.
When operating Linux servers, you often need to check disk space; typically you use df -lh to view total and used space of each mounted filesystem, or du -sh [directory] to calculate the space occupied by all files in a specific directory. When using df and du , you may encounter inconsistent disk usage reports. For example, du may report that the total size of files under the root directory is 2 GB, while df shows that the mounted disk’s used space is 3 GB, 20 GB, or even more. This discrepancy can be caused by three reasons: 1. Reserved space To guard against emergencies, the Linux ext filesystem reserves a portion of disk space. The reserved amount can be viewed with tune2fs -l [dev_name] | grep "Reserved block count" (where dev_name is the device name). This reserved space is counted as used by df , causing inconsistency with du . You can adjust the reserved size using tune2fs -m [size] [dev_name] . 2. Phantom files du sums the sizes of files recorded by the filesystem, while df reads usage information from the superblock, reflecting which disk blocks are allocated. If a file is deleted but still held open by a process, du will not count it, but df will still show its blocks as used. Such phantom files and the processes holding them can be identified with lsof | grep deleted . The space is released when the process stops or is killed. 3. Uncounted files If the first two causes are ruled out yet the numbers still differ, another situation may be at play: when a directory containing data is mounted onto a new device, du does not see the pre‑existing data because it resides on the underlying filesystem, but the space is still occupied and counted by df . Consequently, df reports higher usage than du . To resolve this, carefully kill all processes using the directory with fuser -km [directory] , unmount it via umount [directory] , delete the hidden data, and then remount the device ( mount -t [type] [dev] [directory] ).
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
