Tracking down runaway log files, obsolete container image layers, or sprawling database dumps in Linux using traditional tools like du -sh * or df -h frequently feels cumbersome. Piped command combinations require multiple iterations of sorting, formatting, and manual directory descending. ncdu (NCurses Disk Usage) solves terminal storage diagnostics by providing a fast, lightweight, ncurses-based visual browser. It scans local or remote filesystems, displays interactive graphical usage bars, and allows administrators to delete clutter directly from within the terminal window.
Installing ncdu Across Linux Distributions
The ncdu utility is available in the official repositories of all major Linux distributions:
# Ubuntu / Debian
sudo apt update && sudo apt install -y ncdu
# RHEL / CentOS / Fedora / Rocky Linux
sudo dnf install -y ncdu
# Arch Linux
sudo pacman -S ncdu
# Alpine Linux (minimal containers)
apk add ncdu
Running Scans and Understanding Display Layout
To analyze disk consumption in the current directory or a specific filesystem mount:
# Scan current working directory
ncdu
# Scan entire root filesystem while excluding mounted network shares and foreign filesystems
sudo ncdu -x /
The -x flag (or --one-file-system) is critical when inspecting system partitions: it prevents the scanner from crawling through virtual filesystems like /proc, /sys, and mounted NFS or SMB drives.
Once the scan completes, ncdu presents a two-column interactive interface:
- Left Column: Displays disk usage values formatted in human-readable units (KB, MB, GB).
- Center Bar Graph: Graphical hash tags (e.g.,
[#####]) showing the relative percentage of storage consumed by each item relative to its parent directory. - Right Column: Directory and file names. Directories are designated with a trailing slash (
/).
Interactive Keyboard Shortcuts and Navigation
Navigate the scan results effortlessly using standard vim or arrow key bindings:
Up / Down(ork / j): Move the selection cursor between items.Enter: Open and enter the selected directory to inspect subordinate files.Left Arrow(orh): Navigate up to the parent directory.n: Sort entries alphabetically by file name.s: Sort entries by file size (default).c: Toggle display to show item count (total number of files inside the directory tree).i: Display extended file information (UID, GID, permissions, last modified timestamp).d: Delete the currently selected file or directory (prompts for confirmation before issuing unlinks).
Exporting Scan Data for Remote Server Audits
Running interactive scans over high-latency SSH connections on production database servers can be slow. ncdu allows you to export file metadata to a compressed JSON archive and inspect it locally:
# On remote server: scan and export to file without opening GUI
sudo ncdu -1xo- / | gzip > /tmp/server_disk.json.gz
# Download archive to local workstation and browse interactively
gzip -dc server_disk.json.gz | ncdu -f -
This decoupling allows immediate, lag-free terminal browsing while preserving remote server processor cycles.