Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

df Command Guide for Checking Disk Space and Filesystems

df reports how much disk space each mounted filesystem has used, how much is free, and where it’s all mounted — the first command to run when something is “out of space”.


What is df, and Why Use It?

df (“disk free”) reads the filesystem table and prints, per mount point: total size, used space, available space, usage percentage, and what it’s mounted on. It answers the storage-level question that du answers at the file level.

When a program suddenly fails with “no space left on device”, df is where you confirm it — and discover which filesystem is full.

Why Learn df?

  • “No space left on device” errors start here.
  • Inode exhaustion looks identical to disk full — df -i reveals it.
  • Monitoring and scripts parse df output to trigger alerts and cleanups.
  • It shows you mounts: network shares, tmpfs, snap loops — everything occupying the system.

A filesystem can be 100% full while du of its contents adds up to far less — reserved blocks for root, deleted-but-open files, or full inodes all explain the gap. df sees what du can’t.


1. Show All Mounted Filesystems

df -h
  • -h / --human-readable prints sizes in G/M/K. Typical output:
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2  477G  312G  146G  69% /
tmpfs           8.0G   36M  8.0G   1% /dev/shm
  • Use% is the number to watch; 90%+ deserves attention.

2. Check Space for One Path

df -h /var/log
  • Prints the filesystem that contains that path — the right move when a specific service complains, because paths can live on different mounts.

3. Check Inode Usage (Hidden “Full” Disks)

df -i
  • -i / --inodes shows inode counts instead of bytes.
  • A filesystem with 0 free inodes refuses new files even with terabytes free — the classic cause of “full” disks full of millions of tiny files (mail spools, session files). Look for a IUse% near 100%.

4. Show Filesystem Type

df -hT
  • -T / --output with type adds a column: ext4, xfs, nfs, tmpfs…
  • Distinguishing local disks from network mounts matters when deciding where to put data.

5. See Only What You Care About

df -h -x tmpfs -x devtmpfs -x squashfs
  • -x TYPE excludes filesystem types — the cleanest way to hide the noise of pseudo-filesystems and snap loops and see the real disks.

6. Get Machine-Readable Output for Scripts

df -B1 --output=target,avail /
  • -B1 forces byte units; --output= picks exact columns (GNU).
  • A portable numeric check: df -P /var | awk 'NR==2 {print $5}' prints the usage percentage with -P guaranteeing one line per filesystem.

7. Find Why Space Vanished After a Delete

df -h /
lsof +L1 | head
  • If df still shows the disk full after deleting a huge file, the space is held by a process with the file open.
  • lsof +L1 lists open files with link count 0 (deleted but still held) — the standard follow-up to a “I deleted it but nothing changed!” moment.

8. Watch a Directory’s Filesystem Fill Up

watch -n 5 df -h /var
  • Re-runs df every five seconds — a quick, honest way to watch a runaway log or upload eat the disk while you investigate.

9. Compare Available vs Free (Reserved Blocks)

df -h /
  • On ext filesystems, ~5% is reserved for root by default, so “Avail” is smaller than “Size − Used”.
  • Regular users can never cross that line; only root can write into the reserved pool. This is why a non-root process hits “no space” before the disk is truly full.

10. Show the Device Behind Each Mount

df --output=source,fstype,size,used,avail,pcent,target
  • Explicit column selection (GNU) is the stable way to build reports — column positions shift between implementations, but --output names never do.

Common Pitfalls

  • df reports the filesystem, not the directory. df -h . tells you about the mount containing ., which may be shared with half the system.
  • Full ≠ out of inodes. Always check df -i when a disk with free space refuses files.
  • Deleted files may still count. df shows space held by open-deleted files; restart the process to reclaim it.
  • df without flags uses 1K or 512-byte blocks depending on platform — always pass -h when reading by eye, or -B1/--output when parsing.

CommandDescription
duWhich files and directories eat the space
lsofFind processes holding deleted files open
mountList and manage mounts
lsblkBlock devices and their partitions
findHunt down the giant files df counted

df Cheatsheet

CommandWhat It Does
df -hAll filesystems, human-readable
df -h /var/logFilesystem containing a path
df -iInode usage (the hidden “disk full”)
df -hTInclude filesystem type
df -h -x tmpfs -x squashfsHide noise filesystems
df -P / | awk 'NR==2{print $5}'Usage percentage, script-safe
df -h --output=source,size,avail,targetExplicit columns
watch -n 5 df -h /Watch a filesystem fill up