Running out of disk space on a Linux server or desktop can lead to disastrous consequences. If the root partition fills up entirely, the operating system may become unstable, databases will crash, and you might even be locked out of SSH access. Unlike Windows or macOS, which offer graphical storage managers that neatly categorize your files, finding what is consuming your storage on a headless Ubuntu server requires a bit of command-line detective work.
Fortunately, Linux provides incredibly powerful built-in tools that allow you to locate massive files and bloated directories in seconds. Here is how to find out exactly where your disk space has gone.
Step 1: Check Overall Disk Usage (df)
Before you go hunting for specific files, you need to know which hard drive partition is actually full. The df (disk free) command provides a high-level overview of your mounted file systems.
df -h
The -h flag stands for “human-readable,” which displays the sizes in Megabytes (MB) and Gigabytes (GB) instead of raw bytes. Look at the Use% column to identify which partition is reaching 100% capacity.
Step 2: Find the Largest Directories (du)
Once you know that a partition (for example, the root partition /) is full, you need to drill down to see which specific folders are holding the most data. The du (disk usage) command is the best tool for this job.
To find the largest directories inside the root partition, run this command:
sudo du -a / | sort -n -r | head -n 20
This command looks complex, but it is just a pipeline of three simple actions:
du -a /: Scans the entire root file system and calculates the size of every file and directory.sort -n -r: Sorts the results numerically (-n) in reverse order (-r), putting the largest items at the very top.head -n 20: Limits the output to only the top 20 largest results, preventing your terminal from being flooded with thousands of lines of text.
Step 3: Search for Specific Large Files (find)
If you suspect that a few massive files (like old database backups, rogue log files, or raw video clips) are the culprits, you can use the find command to locate files that exceed a specific size threshold.
For example, to find every single file on your system that is larger than 1 Gigabyte, run:
sudo find / -type f -size +1G
You can adjust the size parameter to suit your needs (e.g., +500M for files over 500 Megabytes). This is often the fastest way to locate a runaway application log file located in /var/log that has suddenly ballooned to 50GB.
A User-Friendly Alternative: ncdu
If you prefer a more visual, interactive interface over typing raw commands, you can install a lightweight utility called ncdu (NCurses Disk Usage). It provides a text-based graphical interface right inside your terminal.
sudo apt install ncdu
sudo ncdu /
It will scan your drive and present a navigable list of directories sorted by size. You can use your keyboard’s arrow keys to dive into folders, press Enter to open them, and press d to immediately delete the file or folder you currently have highlighted.
Conclusion
Mastering these storage commands is a rite of passage for any Linux user. Whether you use the raw power of du and find or the interactive convenience of ncdu, you will never again be caught off guard by a mysteriously full hard drive on your Ubuntu system.