ncdu Command

The ncdu (NCurses Disk Usage) command is a powerful and interactive disk usage analyzer for Linux and Unix-like systems. It provides a fast and easy way to see what's taking up space on your disk, allowing you to navigate through directories and identify large files or folders.

Syntax

ncdu [OPTIONS] [DIRECTORY]

Description

When executed, ncdu scans the specified directory (or the current directory if none is provided) and then presents an interactive, ncurses-based interface. This interface displays a list of directories and files, sorted by size, allowing you to drill down into subdirectories to pinpoint disk space hogs. It's an excellent alternative to du -sh * for visual exploration.

Key features of ncdu:

  • Interactive, text-based user interface.
  • Quickly scans and displays disk usage.
  • Allows navigation into subdirectories.
  • Can delete files/directories from within the interface.
  • Shows percentage of parent directory size.

Common Options

Option Description
-x, --one-file-system Do not cross filesystem boundaries.
-q, --quiet Quiet mode, do not show progress.
-o <file> Export the scanned directory tree to a file (JSON format).
-f <file> Import a directory tree from a file (previously exported with -o).
-r, --read-only Read-only mode (cannot delete files).
-0, --null End lines with NUL characters (for scripting).

Examples

Analyze current directory disk usage

ncdu

Scans the current directory and launches the interactive interface.

Analyze a specific directory

ncdu /var/log

Scans the /var/log directory to analyze its disk usage.

Export scan results to a file

ncdu -o disk_usage.json /home/user/

Scans /home/user/ and saves the results to disk_usage.json in JSON format.

Import and view previously exported results

ncdu -f disk_usage.json

Loads and displays the disk usage information from a previously saved JSON file.

Analyze without crossing filesystem boundaries

ncdu -x /

Analyzes the root filesystem (/) but does not include mounted filesystems (like /home if it's on a separate partition).

See also