Check disk space and find the largest files (df -h, du -sh)
See free space with df -h, find what uses it with du -sh, and list the largest files and folders when a Linux server runs out of space.
df shows how much space each disk has left. du shows how much space a folder uses. Use df to find the full disk, then du to find what filled it.
Find what is filling the disk
- Run df -h and find the disk with a high Use%.
- Go to that disk's top folder and run sudo du -h --max-depth=1 | sort -h.
- Repeat inside the biggest folder until you find the cause.
- If space is free but you still get errors, check inodes with df -i.
Commands you can copy
df -hdf -h /vardf -hTdf -idu -sh foldernamedu -h --max-depth=1 . | sort -hsudo du -xh --max-depth=1 / | sort -hdu -ah . | sort -rh | head -n 10find / -xdev -type f -size +100MReading the output
- -h vs -H
- df -h prints sizes in powers of 1024 (such as 1023M). -H uses powers of 1000. They differ slightly, which explains why numbers do not match other tools.
- df with no argument
- Shows all currently mounted file systems. Name a path to see only the disk that holds it.
- -s and --max-depth
- du -s prints one total per argument. --max-depth=N (or -d N) shows folders only up to N levels down. --max-depth=0 equals -s.
- -x
- Stay on one file system. Without it, du walks into other mounted disks and gives a confusing total.
- -a
- Counts all files, not just folders, so you can find single large files.
- Free space but cannot create files
- The disk may be out of inodes, not bytes. Run df -i.
- du and df disagree
- Deleted files that a program still has open keep using space until the program closes them. Restart the program, such as with systemctl restart.
- Docker is the cause
- Images and containers can fill a disk. See the Docker commands page.
Questions about Disk space commands
- How do I check free disk space in Linux?
- Run df -h.
- How do I find the largest folders?
- du -h --max-depth=1 . | sort -h shows each subfolder, largest last.
- Why does df show a full disk when du shows less?
- Open deleted files, or other mounts, or reserved blocks. Check with du -x and df -i, and restart the program holding deleted files.
- What does No space left on device mean?
- Either no free bytes or no free inodes. Check df -h and df -i.