When a disk fills up, programs fail in odd ways. Two commands answer most questions: df and du.
df: how full is each filesystem
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 79G 72G 2.5G 97% /
tmpfs 7.7G 1.3G 6.5G 16% /tmp-h prints human-readable sizes. Give a path to see only the filesystem that holds it: df -h /var.
Used plus Avail can be less than Size. ext4 normally reserves some blocks (5 percent by default) for root.
du: how big are these files
$ sudo du -sh /var/log
214M /var/log-s prints one total instead of every subdirectory, and -h makes it readable.
To find the biggest directories:
$ sudo du -xh --max-depth=1 /var | sort -h
48M /var/log
310M /var/cache
1.1G /var/lib
1.5G /var-x stays on one filesystem, and sort -h understands sizes like 48M and 1.1G, so the largest end up last.
When df and du disagree
A deleted file that a running program still has open takes up space until the program closes it. df counts it, du cannot see it because it has no name. To look for such files:
$ sudo lsof +L1lsof may need installing. Restarting the program that holds the file releases the space.
Files hidden underneath a mount point can also cause a difference.
Running out of inodes
A filesystem can refuse to create files even with free space, because it has no free inodes. Check with:
$ df -i /
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda2 5242880 1454288 3788592 28% /Millions of tiny files are the usual cause.
Freeing space safely
Do not delete things you do not understand. Common safe targets are package caches (sudo apt clean on Debian and Ubuntu, sudo dnf clean all on Fedora) and old journal logs (sudo journalctl --vacuum-time=2weeks).
Try it
Run df -h and df -i, then use du -sh on a few directories in your home. Pipe du -h --max-depth=1 ~ into sort -h. The packages, disk and FHS lab gives you a shell to practise in.
Check your understanding
Disk Usage
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.