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 -ireveals it. - Monitoring and scripts parse
dfoutput 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
duof its contents adds up to far less — reserved blocks for root, deleted-but-open files, or full inodes all explain the gap.dfsees whatducan’t.
1. Show All Mounted Filesystems
df -h
-h/--human-readableprints sizes inG/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/--inodesshows 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/--outputwith 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 TYPEexcludes 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 /
-B1forces byte units;--output=picks exact columns (GNU).- A portable numeric check:
df -P /var | awk 'NR==2 {print $5}'prints the usage percentage with-Pguaranteeing one line per filesystem.
7. Find Why Space Vanished After a Delete
df -h /
lsof +L1 | head
- If
dfstill shows the disk full after deleting a huge file, the space is held by a process with the file open. lsof +L1lists 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
dfevery 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
--outputnames never do.
Common Pitfalls
dfreports 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 -iwhen a disk with free space refuses files. - Deleted files may still count.
dfshows space held by open-deleted files; restart the process to reclaim it. dfwithout flags uses 1K or 512-byte blocks depending on platform — always pass-hwhen reading by eye, or-B1/--outputwhen parsing.
Related Commands
| Command | Description |
|---|---|
| du | Which files and directories eat the space |
| lsof | Find processes holding deleted files open |
| mount | List and manage mounts |
| lsblk | Block devices and their partitions |
| find | Hunt down the giant files df counted |
df Cheatsheet
| Command | What It Does |
|---|---|
df -h | All filesystems, human-readable |
df -h /var/log | Filesystem containing a path |
df -i | Inode usage (the hidden “disk full”) |
df -hT | Include filesystem type |
df -h -x tmpfs -x squashfs | Hide noise filesystems |
df -P / | awk 'NR==2{print $5}' | Usage percentage, script-safe |
df -h --output=source,size,avail,target | Explicit columns |
watch -n 5 df -h / | Watch a filesystem fill up |