Running out of disk space on a Linux server is a critical emergency. If the root partition fills to 100% capacity, the server cannot write temporary logs, databases will abruptly shut down, and core system services will crash, often locking you out of the machine entirely. As a system administrator, monitoring disk usage is a fundamental daily task.
If you are managing a headless server via an SSH connection, you cannot rely on a graphical file manager to warn you about dwindling storage. Instead, you must use two essential command-line utilities: df (disk free) and du (disk usage). The first tells you the overall health of your drives, while the second acts as a magnifying glass to find exactly which folders are hogging the space.
Method 1: Check Total Disk Capacity (The ‘df’ Command)
The df command (which stands for “disk free”) provides a high-level overview of every storage drive currently attached to your Linux system.
The Basic Command
If you simply type df and press Enter, the terminal will output a table showing all your mounted file systems. However, the data will be presented in raw 1-kilobyte blocks, which is incredibly difficult for humans to read and parse quickly.
The Human-Readable Command
To make the output useful, you must append the -h flag (which stands for “human-readable”).
- Open your terminal application.
- Type the following command and press Enter:
df -h
The output will now display a clean table with sizes translated into Gigabytes (G) and Megabytes (M).
Filesystem Size Used Avail Use% Mounted on tmpfs 1.6G 1.7M 1.6G 1% /run /dev/sda1 50G 45G 2.5G 95% / /dev/sdb1 500G 100G 375G 21% /mnt/data
Look specifically at the Use% column and the Mounted on column. In the example above, the root partition (/), which holds the core operating system, is at a dangerous 95% capacity. The external data drive (/mnt/data) is perfectly healthy at 21% capacity. This tells us we have an immediate problem on the primary drive.
Method 2: Find the Culprit (The ‘du’ Command)
Now that the df command has proven that the root drive is almost full, we need to find out why. Which specific folder is consuming all those gigabytes? For this, we use the du command (which stands for “disk usage”).
Unlike df, which looks at the whole drive, du acts like a vacuum cleaner, sucking up the size of every individual file and folder in a specific directory.
The Search Command
If you suspect the /var/log directory is bloated with old log files, you can target it specifically.
- Type the following command:
sudo du -sh /var/log/* - Press Enter.
How this command works:
sudo: Gives you administrative privileges so the command can calculate the size of protected system files without throwing “Permission Denied” errors.-s: Stands for “summarize.” Without this flag, the command would print thousands of lines detailing every single file. This flag forces it to only print the total size of the top-level folders.-h: Makes the output human-readable (Gigabytes/Megabytes)./var/log/*: Tells the command to look inside the/var/logdirectory and calculate the size of every item (*) inside it.
Sorting the Output
If you run the du command on a massive directory like your home folder, it will spit out a long, unsorted list. To quickly identify the biggest space hogs, you can pipe the output into the sort command.
Type this command and press Enter:
sudo du -sh /home/username/* | sort -rh
This command calculates the size of everything in the user’s home folder, then passes that data to the sort utility. The -rh flags tell the sort utility to look at the human-readable numbers and arrange them in reverse order (largest to smallest). The biggest folder will instantly appear at the very top of the list, allowing you to target it for cleanup.