What is NCDU?
NCDU (NCurses Disk Usage) is a command-line tool that displays disk space usage via an ncurses-based interface. Unlike the classic du, NCDU offers an interactive view that lets you explore directories, see sizes in real time, and delete files or folders directly from the screen. Its lightweight design and speed make it an indispensable ally for system administrators and advanced users who need to quickly identify what is consuming space on their Linux systems.
Installing NCDU
In most Linux distributions, NCDU is in the official repositories. On Debian or Ubuntu run sudo apt update and then sudo apt install ncdu. On Fedora use sudo dnf install ncdu. On Arch Linux the command is sudo pacman -S ncdu. To compile from source, download the tarball, extract it, run ./configure, make, and sudo make install. After installation, invoke the program simply by typing ncdu in the terminal.
Basic Usage of NCDU
When launching ncdu without arguments, the program analyzes the current directory and displays a hierarchical list of subdirectories sorted by size. Each line shows the directory name, its total size, and the percentage relative to the total scanned. Navigate with the up and down arrows to select an entry and press Enter to enter. To go back to the parent level, use the left arrow or the h key. The bottom bar shows the number of files and the free space available.
Navigation Keys and Actions
NCDU has useful shortcuts: use the arrow keys or j/k to move, l to open a directory and h to go up a level. The d key deletes the selected item after asking for confirmation, while c shows the content in detail mode. Press a to toggle between apparent and real size. Finally, q quits the program and returns to the shell.
Visual Representation of Disk Usage
A standout feature of NCDU is its graphical progress bar beside each entry. This bar, made with Unicode characters, intuitively shows the proportion of space occupied by each subdirectory relative to its parent. Colors vary depending on the terminal, but generally warm tones indicate higher consumption and cool tones indicate lower usage. This visualization lets you quickly spot storage “bottlenecks” without reading exact numbers.
Advanced Options and Customization
NCDU accepts several parameters. For example, ncdu -r performs a recursive traversal without crossing mount points. The option ncdu -x has the same effect and is usually enabled by default. To exclude patterns, use ncdu --exclude pattern as many times as needed. With ncdu -o file you save the scan to a file and later load it with ncdu -f file, useful for comparing snapshots at different times.
Comparison with du and Other Tools
The traditional du command provides similar information but in a static, non-interactive format. While du -sh * shows the size of each entry in the current directory, it requires running multiple commands to drill down into subdirectories. NCDU, on the other hand, combines du’s speed with file‑explorer‑style navigation, significantly reducing the time needed to locate large files. Other graphical tools like Baobab or Filelight also offer visualizations, but they depend on a desktop environment and consume more resources, something NCDU avoids by running exclusively in the terminal.
Practical Usage Examples
Imagine you want to find out which of your projects is taking up the most space in your ~/projects folder. Run ncdu ~/projects and, after the analysis, navigate to the subdirectory with the longest bar; there you can see which files are the heaviest and decide whether to check them, archive them, or delete them. Another common case is reviewing the usage of /var/log: by running ncdu /var/log you can quickly identify logs that have grown out of control and apply rotation or deletion according to your retention policies.
Tips and Tricks to Get the Most Out of NCDU
Press the ? key inside NCDU to open the quick help and recall all available shortcuts. If you work with remote servers, combine NCDU with ssh by running ssh user@host ncdu /path to analyze the disk without transferring unnecessary data. To automate reporting, set up a cron job that runs ncdu -o /tmp/scan.ncdu each night and then email the file using mail or any other notification method. Finally, remember that NCDU respects system permissions; if you need to see sizes of directories you lack access to, run the command with sudo.
Conclusion
NCDU has established itself as one of the most effective tools for analyzing disk usage in Linux environments thanks to its combination of speed, interactivity, and low resource consumption. Whether you are a system administrator needing to free space on a production server or a home user wanting to tidy up your downloads folder, NCDU provides the information you need clearly and quickly. Install it today, explore its shortcuts, and discover how much it can simplify your storage management.
This post is also available in ESPAÑOL.