How full is the disk? df and du
See how full a disk is with df -h, find what takes the space with du -sh and sort -h, then free some. Practise on a nearly full disk in your browser.
"No space left on device" is one of the most common errors on any computer. Two commands answer the two questions you'll have.
df: how full is each disk?
df (disk free) lists each disk with its size, what's used and what's left. -h gives sizes like 1.4M or 512G instead of counting kilobytes:
df -hThe Use% column is the one to watch.
du: what is taking the space?
du (disk usage) adds up how much space folders take, including everything inside them. -s gives one total per name and -h readable sizes:
du -sh downloadsdu -sh *With many folders, sort the list so the biggest comes last. sort -h understands sizes like 12K and 1.5M; plain sort -n would put 900K after 1.5M.
du -sh * | sort -hTip:The practice disk is tiny, 2 MB in all, so these files are small. A real disk is thousands of times bigger, and the commands are exactly the same.
Your turn
The disk is filling up. Check how full it is with df -h, find which folder in your home takes the most space with du, delete the three old .iso installers in it (keep everything else), then run df -h again to see the space come back.
Your task
The disk is filling up. Check how full it is with df -h, find which folder in your home takes the most space with du, delete the three old .iso installers in it (keep everything else), then run df -h again to see the space come back.
- See how full the disk is (df -h) (not done yet)
- Compare your folders’ sizes with du (not done yet)
- Delete the three .iso files, keep the rest (not done yet)
- df shows the space is back (under 50% used) (not done yet)
The checklist ticks itself off as you work in the terminal: any way that gets the result counts.
Hints come one at a time, then one way to do it. Try each before the next.
What this lesson uses, in one place.
df -h- Sizes like 2.0M or 512G More on df
du -sh- One total for each folder you name, not every folder inside; sizes like 4.0K, 12K or 1.5M More on du
sort -h- Sort sizes like 4.0K, 12M and 2.1G (what du -h prints) by their real size More on sort
Every everyday command on one page: the Linux commands cheat sheet.