Linux Disk Management: df, du, and Finding What’s Eating Your Storage


Every Linux admin meets the same error eventually: No space left on device. Services crash, logs stop writing, databases refuse to start. The fix is usually quick — if you know where to look. Two commands, df and du, answer two different questions, and confusing them wastes hours.

df: How Full Is Each Filesystem?

df reports free space per mounted filesystem:

df -h
df -hT
df -i

The -h flag is the one you’ll use daily. Watch the Use% column — anything over 85% deserves attention, and 100% is an emergency. A sneaky case: a disk can report 100% full on inodes (df -i) while showing free blocks. That happens when millions of tiny files (runaway logs, cache explosions) exhaust the file count, not the bytes.

du: Which Directories Are Eating the Space?

df tells you a disk is full. du tells you who did it:

du -sh /var/*
du -sh /home/* | sort -h
du -h --max-depth=1 / | sort -h

The classic drill-down: start at /, find the biggest directory, cd in, repeat. In two minutes you’ll usually land on the culprit — most often /var/log, a forgotten backup, or a Docker volume.

The Usual Suspects

  • Logs: journalctl –disk-usage shows how much systemd’s journal holds. Cap it in /etc/systemd/journald.conf with SystemMaxUse=500M.
  • Package caches: sudo apt clean (Debian/Ubuntu) or sudo dnf clean all (Fedora) can free gigabytes.
  • Old kernels: sudo apt autoremove –purge clears kernels you no longer boot.
  • Docker: docker system prune -a removes unused images and containers — check what’s running first.
  • Deleted-but-open files: a process holding a deleted log file keeps its space allocated. lsof | grep deleted finds them; restarting the service frees the space.

The Security Angle

Disk-full isn’t just an uptime problem — it’s a security problem. Attackers deliberately fill disks to stop logging (no logs, no evidence) or crash security tools. A few defensive habits:

  • Separate partitions or quotas for /var/log so a log flood can’t take down the whole system.
  • Set up alerting at 80% and 90% usage — a simple cron job with df and mail beats a 2 AM page.
  • Watch for sudden growth. A home directory that gains 50 GB overnight is worth investigating — it could be a backup gone wrong, or something exfiltrating data to disk first.
  • Rotate logs. logrotate is already installed on most systems; make sure it’s actually running.

A One-Liner to Keep Handy

du -ah /var 2>/dev/null | sort -rh | head -20

That lists the 20 biggest files and directories under /var — usually enough to find your problem in one shot.
Disks fill up. Admins who know df and du fix it in minutes; everyone else reboots and prays. Learn the two commands, set your alerts, and never meet “No space left on device” unprepared again.

Comments

Popular Posts