Running out of disk space on a Linux server is a critical emergency. If the main hard drive fills up completely, essential background services like MySQL databases and Nginx web servers will immediately crash because they cannot write new log files. Worse, you might not even be able to log in to fix the problem.
If you are managing an Ubuntu server via SSH (meaning you do not have a graphical desktop or a File Explorer), you must know how to check your storage capacity using the command line. Fortunately, Linux provides two incredibly powerful commands for this exact purpose: df and du.
Method 1: Check Total Disk Space (The ‘df’ Command)
The df command stands for “disk free.” It provides a high-level overview of every hard drive and storage partition attached to your server, showing how much space is used and how much is available.
If you simply type df and press Enter, the terminal will print the sizes in 1-kilobyte blocks, which is almost impossible for a human to read quickly. Therefore, you should always use the -h flag.
- Open your terminal or SSH client.
- Type the following command:
df -h - Press Enter.
The -h flag stands for “human-readable.” The terminal will output a clean table with sizes displayed in Megabytes (M) and Gigabytes (G). Look for the row where the “Mounted on” column says / (the root directory). This is your primary hard drive. The “Use%” column will instantly tell you if you are in the danger zone (e.g., 95% full).
Method 2: Find Which Folders Are Hogging Space (The ‘du’ Command)
If df -h tells you that your hard drive is full, your next step is to figure out why. The du command stands for “disk usage.” It calculates the exact size of specific directories and the files within them.
Because scanning the entire hard drive can take a long time and output thousands of lines of text, you should use flags to format the output.
- To find out exactly how much space a specific folder is using, use the
-s(summarize) and-h(human-readable) flags:
sudo du -sh /var/log - This will output a single line showing the total size of the
/var/logdirectory.
The Ultimate Storage Troubleshooting Command:
If you have no idea where the massive files are hiding, you can combine du with the sort and head commands to generate a “Top 10” list of the largest folders on your server.
Type this exactly as written:
sudo du -h / | sort -rh | head -n 10
This command scans the entire server (/), sorts the results by size in reverse order (-rh), and then prints only the top 10 results (head -n 10). It is the fastest way to hunt down rogue log files, bloated database backups, or forgotten zip archives that are slowly suffocating your Ubuntu server.