Quick take: Use df -h to see free space on each filesystem and du -sh dir to measure how much a directory is using. Together they answer “is the disk full, and what is filling it?”
Introduction
When a disk fills up, two commands diagnose it: df (disk free) shows how much space each mounted filesystem has, and du (disk usage) shows how much space files and directories occupy. df finds the full partition; du finds what is filling it.
This guide covers reading filesystem usage, measuring directory sizes, finding the biggest offenders, and the inode checks that catch a different kind of “disk full”.
Syntax
The basic syntax of the df and du command is:
df [OPTIONS] [PATH]
du [OPTIONS] [PATH]Common Options and Parameters
The most useful options and parameters for the df and du command:
| Option | Description |
|---|---|
| df -h | Show filesystem usage in human-readable sizes. |
| df -i | Show inode usage instead of bytes. |
| df -T | Also show each filesystem's type. |
| du -h | Human-readable sizes for each item. |
| du -s | Summary — a single total for the path. |
| du -sh * | Total size of each item in the current directory. |
| du --max-depth=1 | Summarise one level deep. |
| du -ah | Include individual files, not just directories. |
Practical Examples
Real df and du commands you can run today:
# Show free space on all filesystems
df -h
# Show free space for one path
df -h /var
# Check inode usage (when df shows space but writes fail)
df -i
# Total size of a directory
du -sh /var/log
# Size of each item in the current directory
du -sh *
# Find the biggest subdirectories
du -h --max-depth=1 /var | sort -hA Disk-Full Troubleshooting Workflow
When a server reports a full disk, df and du together lead you to the cause in a repeatable sequence. Start broad, then drill down:
# 1. Which filesystem is full?
df -h
# 2. Move into it and find the biggest directories
cd /var
sudo du -h --max-depth=1 | sort -h | tail
# 3. Repeat into the largest one until you find the culprit
sudo du -h --max-depth=1 /var/log | sort -h | tail
# 4. If df shows space but writes still fail, check inodes
df -iCommon culprits are runaway log files, old package caches (/var/cache/apt), and forgotten backups. The inode check in step four catches the subtle case where millions of tiny files exhaust the filesystem before the bytes run out.
Tips and Best Practices
- Start with
df -hto find the full filesystem, thendu -sh *inside it to drill down to the culprit. - If
dfshows free space but you still get “No space left on device”, checkdf -i— you may be out of inodes, not bytes. - Pipe du into sort for a ranked view:
du -h --max-depth=1 | sort -hputs the largest directories last.
Final Thoughts
df and du are the two commands that solve a full disk. Use df -h to see which filesystem is full and du -sh to track down the directories consuming it, and remember df -i when space looks fine but writes fail. Together they turn a vague “disk full” alert into a precise, fixable answer.
FAQ: df and du Command in Linux
How do I check free disk space in Linux?+
Run df -h for a human-readable summary of every mounted filesystem, showing size, used, available, and use percentage. Add a path like df -h /var to check one location.
How do I find which directory is using the most space?+
Use du: du -sh * inside a directory shows each item's total, and du -h --max-depth=1 /var | sort -h ranks the subdirectories by size.
What is the difference between df and du?+
df reports free and used space per filesystem from the kernel's view, while du adds up the actual size of files and directories. df finds the full partition; du finds what is filling it.
Why does df show free space but I get 'No space left on device'?+
You may be out of inodes rather than bytes. Run df -i to check inode usage — many tiny files can exhaust inodes while leaving disk space free.
How do I get a single total size for a folder?+
Use du -sh foldername. The -s gives one summarised total and -h makes it human-readable, for example 1.4G.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support