Operations 4 min read

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.

ITPUB
ITPUB
ITPUB
Why df and du Show Different Disk Usage on Linux and How to Fix It

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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

OperationsFilesystemdisk usagedudf
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.