df and du: disk space
"No space left on device." Two commands deal with that message. df tells you how full each disk is. du tells you which folders are taking the space.
df: how full are the disks?
df was not run for this page, as it would describe a real computer. The sample is an illustration.
df -hFilesystem Size Used Avail Use% Mounted on
/dev/sda2 234G 151G 72G 68% /
tmpfs 7.8G 2.1M 7.8G 1% /dev/shm
/dev/sda1 511M 6.1M 505M 2% /boot/efi
/dev/sdb1 932G 610G 322G 66% /media/asha/Backup-h gives sizes in K, M and G. Without it, the figures are in blocks and hard to read.
| Column | Meaning |
|---|---|
| Filesystem | the disk or partition |
| Size | its total size |
| Used, Avail | space used and free |
| Use% | how full it is |
| Mounted on | where it appears in the folder tree |
The line mounted on / is the main disk. Lines called tmpfs are areas held in memory, not on disk, and can be ignored.
df -h . shows only the disk that holds the current folder.
du: what is using the space?
du adds up the space taken by folders.
asha@pc:~/demo$ du -h
1.0K ./old
2.0K ./photos
7.0K .It lists every folder below the current one, with the total for the current folder on the last line. The sample folder is tiny, so the figures are small.
Just the total
-s gives one summary line.
asha@pc:~/demo$ du -sh .
7.0K .
asha@pc:~/demo$ du -sh photos
2.0K photosEach item in this folder
A star gives one line per file and folder here, which answers "which of these is the big one?".
asha@pc:~/demo$ du -sh *
1.0K log.txt
1.0K marks.csv
1.0K notes.txt
1.0K old
2.0K photos
1.0K report.txtOne level only
--max-depth=1 on Linux, or -d 1 on both Linux and the Mac, stops du from listing every nested folder.
asha@pc:~/demo$ du -h -d 1
1.0K ./old
2.0K ./photos
7.0K .Largest first
Pipe the result through sort. -h on sort understands the K, M and G suffixes, and -r puts the largest first.
asha@pc:~/demo$ du -sh * | sort -rh
2.0K photos
1.0K report.txt
1.0K old
1.0K notes.txt
1.0K marks.csv
1.0K log.txtOn a real folder, add | head -10 for the ten largest.
Finding what filled the disk
Work downwards.
df -hto confirm which disk is full.- Go to a likely place, such as your home folder, and run
du -sh * | sort -rh | head. cdinto the largest folder and repeat.- In a few steps you reach the files responsible.
The usual suspects: downloads never cleared, old virtual machine and disk image files, videos, caches of programs and package managers, and log files that have grown without limit.
For single large files, find is quicker: find ~ -type f -size +500M.
Hidden files
du -sh * skips names beginning with a dot, and hidden folders such as .cache can be large. Include them with du -sh .[!.]* *, or simply run du -h -d 1, which counts everything.
Size on disk and size of contents
du reports the space a file occupies on the disk, which is rounded up to whole blocks, so a file of ten bytes may be shown as 4K. ls -l reports the length of the contents. Both are right. They measure different things. du --apparent-size on Linux gives the content size.
When the numbers disagree
Sometimes df says a disk is full and du cannot find the files.
- A program still has a deleted file open. The space is freed only when the program closes. Restarting the program, or the computer, releases it.
- Files are hidden underneath a mounted disk.
- You may not have permission to read some folders. Run
duwithsudoto count everything.
Freeing space safely
Danger. Do not delete things from system folders such as /usr, /var/lib or /System to gain space. Start with your own files: Downloads, the Trash or Bin, old videos and installers.
Package managers have safe clean-up commands. On Debian and Ubuntu, sudo apt clean removes downloaded package files and sudo apt autoremove removes packages no longer needed. On a Mac with Homebrew, brew cleanup does the same.
On a Mac
df -h and du -sh work as described. The Mac's du uses -d 1 for depth, not --max-depth. The Apple menu, About This Mac, then Storage, gives a graphical summary, with suggestions for clearing space.
On Windows, dir shows free space at the end of its listing, and Settings, System, Storage shows what is using the disk.
Examples shown with output were run on 12 November 2026 in a practice folder: Windows commands in cmd.exe on Windows 11, Linux commands with the GNU tools of Git Bash. The folder path and user name were replaced with made-up ones. Commands marked "not run here" are shown as you would type them.
This is an independent learning site. It is not connected with Microsoft, Apple or any Linux distribution. Windows, macOS and other names belong to their owners. Try commands first in a practice folder, never on files you cannot afford to lose.