Monitoring and managing disk usage is important for any Linux user, including Windows and Mac users. The traditional du
(disk usage) command was available. While the du
command was functional, using or checking the disk’s usage was not easy.
Now, we have a new way to analyze disk usage using a new tool/command known as ncdu. This command easily finds directories or software, which is hogging space.
It doesn’t matter if you’re a system admin, developer, or casual user; this tool can save you time and frustration. This article will walk you through what ncdu is, how it works, and how to get the most out of it to make your life a little bit better.
What Is ncdu?
ncdu stands for NCurses Disk Usage. It’s a disk utility that combines the power of the du command with an interactive interface powered by the ncurses library, allowing you to easily explore disk usage in a terminal window.
Initially developed for use on remote servers where graphical tools are impractical, ncdu has become a favorite for anyone who needs a fast and intuitive way to understand what’s taking up space on a file system.
Installation
Installation is simple on most Linux distributions:
Debian/Ubuntu:
sudo apt-get install ncdu
RHEL/CentOS/Fedora:
sudo dnf install ncdu
Arch Linux:
sudo pacman -S ncdu
Why Use ncdu Over du?
While du can report file and directory sizes, it dumps a raw list of data that can be hard to sift through. Here’s what sets ncdu apart:
- Interactive UI: Navigate directories with arrow keys, and delete files directly from the interface.
- Real-Time Filtering: Quickly find the largest files.
- Fast Scanning: This method is more efficient for gathering disk usage data.
- Remote Friendly: Perfect for SSH sessions on headless systems.
Usage
To analyze the current directory:
ncdu
To analyze a specific directory:
ncdu /var/log
You’ll see a sorted list of items in the directory, with their sizes next to them. Use the arrow keys to navigate. Hit Enter to open a directory and Backspace to go up a level. Below, is the output of inside the /aide folder according to above output.
Deleting Files and Directories
While inside ncdu, you can delete files or directories by pressing:
- d to delete the selected item
- y to confirm the deletion
This makes cleanup incredibly efficient—no need to open another terminal window or use rm.
Advanced Features
Exclude Directories or Files
If you want to skip certain files or folders during scanning, use the –exclude flag:
ncdu --exclude Documents
As you can see in the scan, the Documents folder is excluded.
You can also pass patterns:
ncdu --exclude '*.iso'
Scan and Save for Later
You can scan a directory and save the data for later analysis:
ncdu -o scanfile /
Then, analyze it later:
ncdu -f scanfile
This is particularly useful when scanning large filesystems remotely.
Show Hidden Files
By default, ncdu includes hidden files. If you want to ignore them:
ncdu --exclude '.*'
Use Cases
1. Server Maintenance
When a Linux server throws “disk full” errors, ncdu can quickly pinpoint the problem. Log directories, cache folders, or rogue backups can easily go unnoticed—ncdu quickly brings them to the surface.
2. Cleaning Up Developer Machines
Compilers, containers, virtual environments, and downloaded packages can eat up space without you realizing it. A few minutes with ncdu
can clear gigabytes of unnecessary files.
3. Embedded Systems and Raspberry Pi
Knowing where every megabyte is going matters on systems with tight storage constraints. ncdu is lightweight and ideal for these environments.
Performance Considerations
ncdu is efficient, but scanning huge directories can still take time. Here are some tips to improve performance:
- Scan specific subdirectories instead of root (/) when possible.
- Use saved scans for repeated analysis.
- Exclude directories that don’t need to be analyzed (e.g., /proc, /sys, /dev).
Limitations of ncdu
Like any tool, ncdu isn’t perfect:
- It doesn’t track changes to disk usage over time.
- It lacks visualization options like pie charts or graphs (you’ll need something like baobab).
- It’s not multi-threaded, so huge scans can still be slow compared to graphical tools on powerful desktops.
Still, ncdu excels at what it’s built to do—provide a fast, keyboard-friendly view of disk usage.
Conclusion
ncdu doesn’t try to do much by itself. It just gives you a clean, quick, and effective way to understand disk usage. If you’ve ever looked at a “No space left on device” notice and wondered where all your disk space went, try ncdu. It’s simple to set up and use and may help maintain your system lean and clean. Whether you’re a professional system admin or a new Linux user, ncdu is worth adding to your toolbox.