LEARN. PRACTICE. EXPLAIN.
Learning paths & interview practiceP
Linux & CLI troubleshooting foundations
LESSON 3 OF 4 · ABOUT 16 MINUTES + EXERCISE

Why do df and du disagree when a disk fills up?

THE IDEA

What it is

df reports filesystem mount capacity—both disk blocks (df -h) and metadata index nodes called inodes (df -i). du walks visible directories to sum file sizes. They disagree when a file is deleted (unlinked) while a running process still keeps its file descriptor open, or when millions of tiny files exhaust inodes before gigabytes run out.

Why you need it

Simply running rm on a huge active log file does not reclaim disk blocks until the owning process closes the file. Conversely, deleting large backups will not fix an inode exhaustion outage.

How it works

  1. Run df -h and df -i separately to identify whether bytes or inodes are at 100% and which mount is affected.
  2. Compare df mount totals against du -sh on directories inside that mount.
  3. When df shows full but du is small, inspect open unlinked descriptors with lsof +L1.
  4. Reclaim space safely by truncating in place (truncate -s 0) or reloading/restarting the owning daemon—never delete unknown files blindly.
Shell

Finding deleted files still held open

df -h /var/log            # 100% used
du -sh /var/log           # only 120M visible!
lsof +L1                  # shows api-worker holding /var/log/api-debug.log (deleted)
systemctl reload api-worker
df -h /var/log            # space drops immediately

In Unix, unlinking removes the directory name while keeping the inode and data blocks alive until the last open file descriptor closes.

Try the in-browser Linux CLI lab

Practice ls -la, chmod, grep | wc, df -h, df -i, du, lsof, and ss -tulnp against five live troubleshooting missions.

Open Linux CLI lab

Good practices and why

  • Always check BOTH df -h (bytes) and df -i (inodes) when writes fail with ENOSPC.
  • Use truncate -s 0 or logrotate copytruncate/reload when clearing active logs safely.

Common mistakes

  • Running du -sh / across huge network mounts during an outage.
  • Deleting an open log file and assuming the disk space was freed immediately.
GUIDED IMPLEMENTATION

Try it yourself

Complete Missions 3 and 4 in the Linux CLI Lab to resolve both an open-deleted-file block leak and an inode exhaustion incident.

What a successful result looks like

Both /var/log block usage and /tmp inode usage drop cleanly back to healthy levels.

0 / 6000 characters · Saved on this device. Do not include passwords or private data.

Check your understanding

df -h shows /var/log at 100%, but du -sh /var/log shows 120M. What is the likeliest cause?

Answer the understanding check correctly to record exercise completion.

PUT THE IDEA UNDER PRESSURE

Related interview practice

These scenarios add constraints and follow-up questions to the concepts you just learned.

Further reading

Selected primary references · reviewed 2026-10-09. Examples are educational; use your framework’s documented integration guidance when building a deployed system.

AlifBay Prep