One of the most common critical alerts a systems administrator receives is a “Disk Space Full” error. When a Linux server runs out of storage, databases crash, logs fail to write, and web servers go offline. Unlike a desktop OS with visual pie charts, diagnosing storage issues in a headless Linux environment requires terminal utilities. The two most essential tools for this job are the df (Disk Free) and du (Disk Usage) commands.
Used together, these commands act as a funnel. You use df to identify which hard drive or partition is full, and then you use du to drill down into that drive to identify exactly which folders and files are hogging the space. In this guide, you will learn the practical syntax for both commands.
Step 1: Using df to Find the Full Drive
The df command reports the total amount of available and used disk space on your file systems. If you run df without any flags, it outputs storage in raw 1-kilobyte blocks, which is nearly impossible for a human to read.
Always append the -h (human-readable) flag. This converts the raw blocks into Megabytes (M) and Gigabytes (G).
df -h
The output will display several columns. The most critical are:
- Filesystem: The physical hardware name (e.g.,
/dev/sda1) or logical volume. - Size / Used / Avail: The total capacity, how much is consumed, and what remains.
- Use%: The most important column. Look for any drive approaching 90% or higher.
- Mounted on: Where the drive lives in your directory structure (e.g.,
/for the root OS, or/var/logfor logging).
Once you identify a mount point (like /) that is 98% full, you move to Step 2.
Step 2: Using du to Hunt Down Large Folders
The du command calculates the disk space used by a specific directory and all of its subdirectories. If you just type du, it will aggressively list every single file on the system, overwhelming your screen.
To find the culprit, you need to summarise the data. Use the -s (summarise) and -h (human-readable) flags together. You should also run this command with sudo, otherwise you will receive “Permission denied” errors for system folders.
To see the total size of specific top-level directories in your root drive:
sudo du -sh /var /etc /home
Output:
20G /var
12M /etc
2.5G /home
The Deep Dive Combination
In the example above, the /var directory is massive (20G). Now, you need to see what is inside /var. To do this efficiently, you can combine du with the sort command to automatically list the heaviest folders at the bottom of your screen.
sudo du -sh /var/* | sort -h
This command asks Linux to calculate the size of every folder inside /var (using the * wildcard), and then pipe (|) that data into a human-readable sort. The output might reveal:
4K /var/empty
10M /var/cache
19.9G /var/log
You have now successfully identified that the /var/log directory is responsible for the space issue. You can repeat the command (sudo du -sh /var/log/* | sort -h) to drill down further and find the exact log file (e.g., a runaway syslog or nginx/access.log) that needs to be deleted or rotated.
By mastering the one-two punch of df -h and du -sh, you can resolve critical Linux storage outages in a matter of minutes.