How to Check Disk Space in Linux
See how much space is left, and find out what is using it.
"Is the disk full?" and "what filled it?" are two different questions with two different tools. df answers the first by asking each filesystem for its counters — instant, authoritative. du answers the second by walking directories and adding up what it finds — slower, but it tells you where to look. Almost every disk investigation uses them in that order.
Step by step
1 See the overall picture
$ df -h One line per filesystem: size, used, available, percentage and mount point. The -h makes the numbers human (G, M) instead of blocks. Note that /home, /var and /boot are often separate filesystems, so "the disk" may be full while another has plenty of room.
2 Check the filesystem you actually care about
$ df -h /var/log Pass a path and df reports only the filesystem holding it. This avoids the classic mistake of reading the wrong row.
3 Find the biggest directories
$ du -h --max-depth=1 /var | sort -hr | head Sizes of each subdirectory, largest first. Enter the biggest one and repeat — three or four rounds usually corner the culprit. This drill-down is the standard technique.
4 Find the biggest individual files
$ find / -xdev -type f -size +500M -exec ls -lh {} + 2>/dev/null | sort -k5 -hr | head Everything over 500 MB, largest first. The -xdev keeps the search on one filesystem, and 2>/dev/null hides the permission noise.
5 Check inodes if the numbers make no sense
$ df -i A filesystem can be full with free bytes: every file consumes an inode, and millions of tiny files exhaust them. If IUse% is at 100% while Use% is not, deleting files (not freeing bytes) is the fix.
Tips worth knowing
- Install `ncdu` and use it instead of du for interactive exploration: arrow through directories sorted by size and delete on the spot.
- On development machines, suspect Docker first: `docker system df` then `docker system prune -a --volumes`.
- If df and du disagree, a deleted file is still held open by a process. Find it with `sudo lsof +L1` and restart the process.
- Truncate active logs rather than deleting them: `sudo truncate -s 0 /var/log/big.log`. Deleting a file a process has open frees nothing.
Frequently asked questions
What is the difference between df and du?
df asks the filesystem how much space it has (fast, includes everything). du adds up the files it can reach by name (slower, blind to deleted-but-open files). Use df to confirm the problem and du to locate it.
Why does df show 100% when I deleted files?
The space is not released until every process holding those files closes them. sudo lsof +L1 lists them; restarting the process frees the space.
What does the "Use%" of a filesystem mean exactly?
Used blocks over total, but ext4 reserves about 5% for root by default — which is why you can hit "disk full" as a normal user at around 95%.
If it goes wrong
The commands behind it
See free space per filesystem and find what is eating your disk, directory by directory.
findLocate files anywhere in a directory tree by name, type, size, date — and act on them.
rmDelete files and directories — and understand -r, -f and why there is no trash bin.
Concepts involved: Inode · Mount
More how-to guides
Unpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.
Free a port that is already in useFind which process holds a port and stop it cleanly.
Find and replace text in filesReplace text in one file or across a whole project, safely.
Make a script executableGive a script permission to run, and understand why it needs it.