Running out of hard drive space on a headless Linux server is a terrifying experience. When a server’s disk hits 100% capacity, critical services (like MySQL databases) will instantly crash because they can no longer write temporary lock files. Because you don’t have a graphical file manager like Windows Explorer, you cannot simply right-click folders to see how big they are.
You must use the terminal to hunt down the massive log files, abandoned database backups, or bloated user directories that are consuming your space. The two best tools for this job are the find command (for targeting specific file sizes) and the du command (for seeing which folders are the heaviest).
Method 1: The “find” Command (The Precision Strike)
If you suspect that a single, monolithic file (like an old 50GB .tar.gz backup archive or a runaway error.log) is choking your server, the find command is the fastest way to locate it.
The find utility can scan your entire hard drive and print out the exact path of any file that exceeds a specific size threshold.
- Open your terminal and type this command exactly:
sudo find / -type f -size +500M -exec ls -lh {} +
- Press Enter.
Here is what this extremely powerful command actually does:
sudo: Gives the command root privileges (so it can look inside restricted system folders).find /: Tells the utility to start searching from the absolute root directory of the hard drive.-type f: Tells the utility to only look for files, completely ignoring folders.-size +500M: The core parameter. It tells the utility to only return files that are larger than 500 Megabytes. (You can change this to+1Gfor Gigabytes).-exec ls -lh {} +: Instead of just printing a messy list of file paths, this tells the utility to pass the results through thels -lhcommand, which formats the output into a beautiful, human-readable list showing the exact size, owner, and date modified of each massive file.
Method 2: The “du” Command (The Folder Breakdown)
The find command will not help you if your storage is being consumed by a single folder containing a million tiny 1-Megabyte image files. To see the cumulative size of entire directories, you must use the du (Disk Usage) command.
- Navigate to the top-level directory you want to investigate (e.g., type
cd /var/wwwto investigate your web server). - Type this command:
sudo du -sh * | sort -rh
- Press Enter.
This is a combination of two commands piped together:
du -sh *: Calculates the total size of every item in your current directory. The-sstands for summary (so it doesn’t print a billion lines of sub-folders), and the-hstands for human-readable (Megabytes and Gigabytes).sort -rh: Takes that data and sorts it in reverse order (heaviest items at the very top).
The terminal will print a clean, sorted list. If you see that the /var/www/backups folder is consuming 40GB, you can use cd backups to jump into it, and then run the exact same du command again to dig deeper into the structure until you find the exact source of the bloat.
Method 3: The “ncdu” Utility (The Interactive Dashboard)
If you hate typing complex grep and sort pipes, there is a vastly superior alternative. The ncdu (NCurses Disk Usage) tool is a lightweight, interactive dashboard that visualizes your hard drive directly in the terminal.
- First, you must install it. Type
sudo apt install ncdu(Ubuntu/Debian) orsudo yum install ncdu(CentOS/RHEL). - To scan your entire server, type:
sudo ncdu / - Press Enter.
The utility will take a few seconds to scan the drive. The terminal will then transform into a beautifully organized, interactive interface. The heaviest folders are pinned to the top, complete with visual bar graphs showing their size.
You can use the Arrow Keys to scroll up and down the list. Press the Enter key to dive into a heavy folder, and press the Left Arrow key to back out. If you find a massive, useless file, you can highlight it and press the d key to delete it immediately. To quit the dashboard, press the q key.