When a Linux server’s hard drive suddenly hits 100% capacity, identifying exactly which folders are hoarding the space is a frustrating challenge. The standard du -sh * command takes a long time to run, outputs a massive, unorganized wall of text, and requires you to manually parse through the gigabyte measurements to find the culprit. To instantly visualize your disk usage in a fast, interactive, sortable terminal interface, you must ditch the standard commands and install ncdu (NCurses Disk Usage).
How to Install and Launch ncdu
Because ncdu is an interactive visualizer (similar to htop for CPU usage), it is rarely installed by default on bare-metal server distributions.
To install it on Debian/Ubuntu systems, open your terminal and run:
sudo apt install ncdu
Once installed, you can launch the analyzer simply by typing ncdu and pressing Enter. By default, it will scan whatever directory you are currently sitting in. If you want to scan the entire root filesystem of the server (which requires root privileges to read system files), run:
sudo ncdu /
The application will briefly display a scanning progress bar. Once the scan completes, your terminal will transform into a fully interactive graphical dashboard.
How to Navigate the ncdu Dashboard
The ncdu interface is designed entirely for keyboard navigation; your mouse will not work here.
- Sorting: The directories are automatically sorted by size, with the absolute largest folder sitting at the very top of the list. You will see the exact size (e.g., 45.2 GiB) alongside a visual progress-bar-style graph indicating its relative weight.
- Drilling Down: Use the Up and Down arrow keys to highlight a massive folder (like
/var). Press the Right arrow key (or Enter) to dive inside that folder. You will instantly see the sub-folders (like/var/logor/var/lib) sorted by size again. This allows you to rapidly drill down through layers of directories until you find the exact file causing the problem. - Going Back: Press the Left arrow key to exit a directory and move back up the folder tree.
How to Safely Delete Files
When you finally locate the massive log file or forgotten backup archive that is destroying your disk space, you do not need to exit ncdu to delete it.
- Use your arrow keys to highlight the specific file.
- Press the d key on your keyboard.
- A bright red warning popup will appear, asking you to confirm the deletion. Use the arrow keys to select “yes” and press Enter.
The file is permanently deleted, and ncdu will instantly recalculate the total disk space available on the server. When you are finished cleaning your drive, press q to quit the application and return to your standard bash prompt.