Q: The `du -sh /` and `df -h` commands show significantly different disk usage values. `df` shows 90% used, but `du` reports only 60% of the disk in use. What explains this discrepancy?
The du and df commands measure disk usage differently:
Want to master this scenario in a live sandbox? The Linux Foundation's Certified System Administrator (LFCS) & SRE Track covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: "Never reboot a server blindly; always capture top process telemetry, lsof descriptors, and thread dumps first. The interviewer is testing: Understanding of deleted-but-open files, reserved blocks, filesystem internals.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."
Initial Diagnostics & Root Cause Analysis
The du and df commands measure disk usage differently:
duwalks the directory tree and sums up the sizes of files it can see (existing directory entries).dfqueries the filesystem's superblock, which tracks total allocated vs. free blocks.- Deleted files still held open by processes: When a file is deleted (
rm) but a process still has it open,ducan't see it (directory entry is gone), butdfstill counts the blocks as used. Fix:lsof +L1finds files with zero links (deleted but open). Restart the process or truncate via/proc/./fd/
Remediation & Permanent Safeguards
Common causes of discrepancy:
- Reserved blocks: ext4 reserves 5% of the partition for root by default.
dfaccounts for these reserved blocks;dudoesn't know about them. Check withtune2fs -l /dev/sda1 | grep "Reserved block count". Reduce if needed:tune2fs -m 1 /dev/sda1(sets reserved to 1%). - Filesystem journal: The ext4 journal consumes space visible to
dfbut notdu.
- du walks the directory tree and sums up the sizes of files it can see (existing directory entries).
- df queries the filesystem's superblock, which tracks total allocated vs. free blocks.
- Deleted files still held open by processes: When a file is deleted (rm) but a process still has i...
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Issuing immediate kill -9 (SIGKILL) commands rather than allowing graceful termination via kill -15 (SIGTERM) when configuring commands show significantly SIGKILL immediately halts execution without allowing processes to flush memory buffers, commit database transactions, or remove stale PID locks.
-
Overlooking file system inode exhaustion (df -i) when diagnosing 'No space left on device' errors when configuring commands show significantly
Millions of small files or unrotated session tokens can exhaust available file system inodes even when standard disk storage (
df -h) shows ample free space. - Exhausting open file descriptor allocations (ulimit -n) under intensive concurrent socket connections when configuring commands show significantly Reaching file descriptor exhaustion throws 'Too many open files' errors, preventing services from accepting new TCP client socket connections.
-
Permitting defunct zombie processes to accumulate without fixing parent process SIGCHLD waitpid reaping when configuring commands show significantly
Zombie processes consume process table entries; accumulating zombies can exhaust the system maximum PID limit (
pid_max).