Managing storage efficiently is crucial for system administrators and developers using Linux. One of the best tools for analyzing disk usage is NCDU (NCurses Disk Usage), a fast and interactive alternative to du
. It provides a detailed breakdown of directory sizes, allowing users to identify large files and optimize disk space effortlessly.
What is NCDU?
🔹 NCDU (NCurses Disk Usage) is a powerful command-line utility that visualizes disk usage interactively.
🔹 It is significantly faster than traditional tools like du
and provides a user-friendly navigation interface.
🔹 Using NCDU in Linux, users can efficiently analyze disk space, locate large files, and free up unnecessary storage.
Originally developed for minimal Linux environments, NCDU has now become an essential tool for managing disk usage effectively.
How to Install NCDU in Linux?
Installing NCDU is straightforward and varies based on the Linux distribution.
For Ubuntu/Debian-based systems, run:
sudo apt update && sudo apt install ncdu -y
For CentOS/RHEL, enable the EPEL repository and install:
sudo yum install epel-release -y
sudo yum install ncdu -y
For Arch Linux, use:
sudo pacman -S ncdu
Once installed, you can start using NCDU to check directory sizes and optimize storage usage.
How to Check Directory Size Using NCDU?
The simplest way to analyze a directory is by running:
ncdu /path/to/directory
For example, to check the disk usage of the home directory:
ncdu ~/
This command scans the directory and displays an interactive interface where users can navigate and identify large files.
To scan the entire root filesystem, use:
sudo ncdu /
This helps locate unusually large directories and optimize system storage efficiently.
Understanding the NCDU Interface
When NCDU completes scanning, it presents a sortable list of directories and files based on size. The navigation controls are:
🔹 Arrow Keys – Move up/down to navigate directories.
🔹 Enter Key – Drill down into a selected directory.
🔹 d Key – Delete selected files or directories.
🔹 q Key – Quit the application.
This interactive feature makes NCDU one of the best tools for quickly managing disk space.
Advanced NCDU Usage for Better Disk Management
1. Scan and Save Results for Later Use
Instead of scanning the directory repeatedly, store results in a file using:
ncdu -o output-file.ncdu /
Later, view the saved scan without rescanning:
ncdu -f output-file.ncdu
This feature is helpful for analyzing disk usage on remote servers without an active internet connection.
2. Exclude Directories from Scanning
To ignore specific directories, use:
ncdu --exclude /var/log /
This ensures unnecessary files are excluded from disk usage reports.
3. Delete Large Files Directly from NCDU
After identifying large files, remove them directly by pressing d
inside NCDU. Use caution when deleting files to avoid unintended data loss.
Common Issues and Their Solutions
1. NCDU Not Found After Installation
✔ Ensure the package is installed correctly by running:
which ncdu
✔ If not found, reinstall using the package manager.
2. Permission Denied When Scanning Root Directory
✔ Running NCDU on system directories requires sudo privileges:
sudo ncdu /
✔ Consider using ncdu --exclude
to scan only user-accessible folders.
3. Large Disk Takes Too Long to Scan
✔ Use the -q
flag to reduce unnecessary output and speed up scanning:
ncdu -q /
✔ For massive storage, scan incrementally using the -o
option.
Why Choose NCDU Over DU for Checking Directory Sizes?
Feature | NCDU | DU |
---|---|---|
Speed | ✅ Fast | ❌ Slower |
Interactivity | ✅ Yes | ❌ No |
Sorting Options | ✅ Yes | ❌ No |
Deletion Support | ✅ Yes | ❌ No |
Remote Scanning | ✅ Supported | ❌ Not Ideal |
Unlike du
, which simply prints directory sizes in the terminal, NCDU provides an interactive, user-friendly interface for managing storage.
Final Thoughts
Using NCDU to check directory sizes in Linux provides a fast, efficient, and interactive way to manage disk usage. Whether you’re a system administrator or a casual Linux user, mastering NCDU will help you identify large files, free up space, and keep your system optimized.
Start using NCDU today to take full control of your Linux disk space and manage directories effortlessly!