df
Report free and used disk space on mounted filesystems
By CMD Script Team · 4 min read · Last updated
df [OPTIONS] [FILE...]Options
| Flag | Description |
|---|---|
-h | Print sizes in human-readable units (K, M, G) instead of raw block counts |
-T | Show the filesystem type (ext4, xfs, tmpfs, etc.) in an extra column |
-i | Report inode usage and availability instead of block/space usage |
-a | Include pseudo, duplicate, and inaccessible filesystems normally omitted |
-t TYPE | Limit output to filesystems of the given type, e.g. -t ext4 |
-x TYPE | Exclude filesystems of the given type, e.g. -x tmpfs |
Distribution compatibility
- Ubuntu
- Debian
- Fedora
- Arch
- macOS (BSD df, fewer GNU-style long options)
What it does
df (disk free) reports how much space is used and available on each mounted
filesystem, as the kernel accounts for it. Run with no arguments, it lists every
currently mounted filesystem; given a file or directory path, it reports only the
filesystem that path lives on. It's the go-to command for answering "am I about to run
out of disk space?" at the filesystem level, as opposed to du, which answers "which
files or directories are using the space?"
Beginner examples
df— list all mounted filesystems with raw block countsdf -h— same, but with human-readable sizes like12Gor340Mdf -h /— check usage on just the root filesystemdf -h /home— check usage on whichever filesystem/homeis mounted ondf -T— add a column showing each filesystem's type (ext4, xfs, tmpfs, etc.)
df -h
Advanced examples
- Show type and human-readable sizes together:
df -hT - Check inode usage instead of block usage:
df -i - Exclude noisy pseudo-filesystems like tmpfs and devtmpfs:
df -h -x tmpfs -x devtmpfs - Limit output to a specific filesystem type:
df -h -t ext4 - Combine with
awkto alert when usage crosses a threshold:df -h --output=pcent,target | awk 'NR>1 && $1+0 > 90'
df -hT | grep -v tmpfs
Common mistakes
- Confusing
dfwithdu—dfreports whole-filesystem usage,dureports usage of specific files/directories; they can disagree, especially when a deleted file is still held open by a process (df counts it, du can't see it). - Reading raw block counts instead of adding
-h, making sizes hard to interpret at a glance. - Assuming free space means you can create more files — if inodes are exhausted (
df -ishows 100%), you'll get "No space left on device" even with free bytes available. - Forgetting that bind mounts and network filesystems (NFS, tmpfs) show up in plain
dfoutput and can clutter results — use-xto exclude types you don't care about.
Tips
- Use
df -has a first check whenever a process fails with a disk-space-related error. - Pair
df -iwithdf -hwhen debugging "no space left" errors on filesystems full of tiny files (e.g. mail queues, session caches) — inode exhaustion looks identical to space exhaustion from the application's point of view. df -hTis a good habit for quickly seeing whether a mount is the type you expect (e.g. confirming a volume mounted as ext4 rather than falling back to tmpfs).- Script periodic checks with
df --output=pcent,targetfor clean, parseable output.
Best practices
- Monitor
df -houtput for critical mount points (/,/var,/home) as part of routine system health checks or alerting. - Check both block usage (
df -h) and inode usage (df -i) when diagnosing "disk full" symptoms — they're independent resources. - Exclude ephemeral pseudo-filesystems (tmpfs, proc, sysfs) from usage reports to avoid false alarms in monitoring scripts.
- Use a specific path argument (
df -h /var/log) rather than parsing the full listing when you only care about one mount.
Try it yourself
A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.
Real-world use cases
- Diagnosing why a deployment or database failed with a disk-space error.
- Setting up a monitoring alert that pages when any filesystem exceeds 90% usage.
- Verifying a newly attached volume mounted correctly and with the expected filesystem type before writing data to it.
- Investigating "No space left on device" errors that turn out to be inode exhaustion rather than block exhaustion.
Common interview questions
- What's the difference between df and du? df reports space usage per mounted filesystem as tracked by the kernel; du reports space used by specific files or directories you point it at by walking the directory tree.
- Why might df show a filesystem as full even after you delete files? If a process still has the deleted file open, the kernel doesn't reclaim the space until the file handle is closed, so df continues to count it as used.
- How do you check for inode exhaustion? Run df -i, which reports inode usage and availability instead of block usage — a filesystem can be 100% full on inodes while still showing free space in blocks.
- How would you find which mount point a given directory belongs to? Run df on that path, e.g. df -h /var/log/myapp, and df resolves it to the underlying mounted filesystem.
Frequently Asked Questions
How do I see disk usage in a human-readable format?
Run df -h. It converts raw 1K-block counts into readable units like 4.2G or 512M.
What's the difference between df -h and du -h?
df reports space usage for entire mounted filesystems (as the kernel sees them), while du reports space used by specific files and directories you point it at. A filesystem can show high df usage from files du won't see, e.g. deleted files still held open by a running process.
Why does df show 100% inode usage while there's still free space?
Filesystems have a fixed number of inodes set at creation time. If a directory holds huge numbers of tiny files, you can exhaust inodes long before you exhaust disk blocks. Use df -i to check inode usage separately from space usage.
How do I check disk space for just one filesystem?
Pass a path on that filesystem as an argument, e.g. df -h /var, and df reports only the filesystem containing that path.
Cheat sheet
Download a quick-reference cheat sheet for df.