When Linux servers or workstations run low on storage, system administrators often turn to the traditional du (Disk Usage) and df (Disk Free) command-line utilities. However, piping du -sh * | sort -h across deep directory hierarchies produces unwieldy text streams that make spotting hidden log files, abandoned Docker volumes, or bloated package caches tedious. The ncdu (NCurses Disk Usage) tool provides a fast, interactive ncurses-based terminal interface that lets you navigate folder structures, sort items by size, and safely delete disk hogs without leaving your shell session.
Installing ncdu Across Major Linux Distributions
Because ncdu is written in C and depends solely on the lightweight ncurses library, it installs quickly across all major distribution repositories:
On Debian, Ubuntu, and Linux Mint:
sudo apt update && sudo apt install -y ncdu
On RHEL, Rocky Linux, AlmaLinux, and Fedora:
sudo dnf install -y ncdu
On Arch Linux and Manjaro:
sudo pacman -S ncdu
Running and Navigating ncdu
To analyze the current working directory, simply run:
ncdu
To scan the entire root filesystem while preventing ncdu from crossing into remote NFS mounts or virtual filesystem pseudofiles (such as /proc and /sys), pass the -x flag:
sudo ncdu -x /
Essential Keyboard Shortcuts in the ncdu Interface:
- Up / Down Arrow (or j / k): Move selection up and down the file list.
- Enter (or Right Arrow): Open and drill down into the selected directory.
- Left Arrow: Return to the parent directory.
- d: Prompt to delete the currently selected file or folder immediately (requires appropriate file permissions).
- s: Sort by file size (toggles descending/ascending).
- c: Sort by total child item count.
- n: Sort alphabetically by item name.
- g: Toggle percentage bar display (percentage graph, numerical graph, or hidden).
- i: Display detailed file information (path, disk usage, apparent size, inode count).
- q: Quit ncdu.
Exporting and Analyzing Large Scans Offline
On production database hosts or systems with multi-terabyte arrays, performing live interactive scans can strain disk I/O. ncdu allows you to decouple scanning from analysis by exporting directory indices to a compressed file:
1. Export Disk Metadata to a File in the Background
sudo ncdu -x -1 -o /tmp/disk_audit.ncdu /var
The -o parameter writes the scan results to a designated file, while -1 minimizes console output updates to save CPU cycles.
2. Open the Saved Scan Interactively
ncdu -f /tmp/disk_audit.ncdu
This command loads the index instantaneously without generating any further disk read I/O, allowing you to browse storage hierarchies seamlessly.
Excluding Cache and Temporary Directories from Scans
You can instruct ncdu to bypass non-actionable directories (such as git internal objects or runtime caches) using the --exclude parameter:
sudo ncdu --exclude "/var/cache" --exclude "*/.git" /var
This keeps your scan focused strictly on actionable user data, container overlays, and persistent application logs.