LinuxCommandLibrary

ncdu

Analyze disk space usage interactively

TLDR

Analyze the current working directory

$ ncdu
copy

Colorize output
$ ncdu --color [dark|off]
copy

Analyze a given directory
$ ncdu [path/to/directory]
copy

Save results to a file
$ ncdu -o [path/to/file]
copy

Exclude files that match a pattern, argument can be given multiple times to add more patterns
$ ncdu --exclude '[*.txt]'
copy

SYNOPSIS

ncdu [options] [directory]

ncdu -f file [options]

PARAMETERS

-x, --one-file-system
    Do not cross filesystem boundaries. Only scan files on the same filesystem as the starting directory.

-q, --quiet
    Enable quiet mode. Don't show progress or errors during the scan.

-v, --version
    Show the version of ncdu and exit.

-h, --help
    Display a help message and exit.

-o FILE, --output FILE
    Export the scanned analysis to a file, which can be later viewed with -f.

-f FILE, --input FILE
    Read analysis from a previously saved file instead of scanning the disk.

-r, --read-only
    Start in read-only mode, disabling any file deletion options.

-0, --null
    When exporting to a file, use null separators for directory paths (useful for scripting).

-1, --no-confirm
    Do not ask for confirmation when deleting files (use with extreme caution).

-a, --apparent-size
    Display apparent size instead of disk usage (size of file content, not including disk overhead).

-L, --follow-symlinks
    Follow symbolic links and count their target's size.

-e PATTERN, --exclude PATTERN
    Exclude files or directories matching the specified pattern.

-X FILE, --exclude-from FILE
    Read exclude patterns from the specified file, one pattern per line.

-p, --progress
    Force showing the scanning progress during startup, even if output is redirected.

-P, --no-precalc
    Do not precalculate directory sizes during the initial scan (may be slower).

-s, --si
    Use SI units (powers of 1000) for disk usage instead of binary units (powers of 1024).

-u, --no-unicode
    Do not use Unicode drawing characters, fallback to ASCII instead.

DESCRIPTION

ncdu (NCurses Disk Usage) is a fast, easy-to-use disk usage analyzer designed for command-line environments. It provides an interactive, ncurses-based graphical interface that allows users to quickly scan and browse disk space usage. Unlike traditional command-line tools like du, ncdu offers an intuitive tree-like view of directories and files, enabling users to navigate through the filesystem, identify large files or directories, and even delete them to free up space directly from the interface. It's particularly useful for quickly diagnosing disk space issues on servers or systems without a graphical desktop environment, providing real-time feedback and efficient navigation through large directory structures. Its speed and interactivity make it a popular choice for system administrators and users looking to manage disk space effectively.

CAVEATS

ncdu requires an ncurses-compatible terminal. While it offers file deletion capabilities, it's crucial to exercise extreme caution as deletions are permanent and cannot be undone. The disk usage reported by ncdu might sometimes differ from other tools like du due to differing default block sizes, handling of sparse files, or whether apparent size versus actual disk usage is displayed. Running ncdu on extremely large directory structures can still consume significant system resources during the initial scan.

INTERACTIVE CONTROLS

ncdu offers a rich set of interactive keyboard controls for navigation and actions:
Arrow keys: Navigate up/down/left/right.
Enter: Go into selected directory.
Backspace: Go to parent directory.
d: Delete selected file or directory (prompts for confirmation unless -1 is used).
g: Toggle display of percentage bars and graphs.
s: Sort by size (toggle ascending/descending).
n: Sort by name (toggle ascending/descending).
C: Sort by items (number of files/directories within, toggle ascending/descending).
M: Sort by last modified time (toggle ascending/descending).
A: Toggle apparent size vs. disk usage.
r: Rescan current directory.
?: Show help screen with all controls.
q: Quit ncdu.

UNDERSTANDING DISK USAGE VS. APPARENT SIZE

By default, ncdu displays the disk usage, which is the actual amount of disk space occupied by a file or directory. This accounts for the filesystem's block size, sparse files, and other overhead. The apparent size (toggled with 'A' key or -a option) refers to the logical size of the file, i.e., the number of bytes in its content. For most files, these values are similar, but for sparse files, files on filesystems with large block sizes, or files with hard links, they can differ significantly. When trying to free space, disk usage is usually the more relevant metric.

HISTORY

ncdu was created by Yoran Heling around 2007-2008 as a tool to address the need for a fast, interactive way to analyze disk space usage directly from the command line, especially on remote servers where graphical tools were unavailable. It was designed to provide a user-friendly ncurses interface similar to the popular du command, but with the added benefits of interactive navigation, sorting, and direct file deletion. Its development aimed to offer a more efficient alternative to repeatedly running du with various options to pinpoint disk space hogs. Over the years, it has gained widespread adoption among system administrators and power users for its simplicity, speed, and effectiveness in managing disk space.

SEE ALSO

du(1): Estimate file space usage., df(1): Report file system disk space usage., find(1): Search for files in a directory hierarchy., tree(1): List contents of directories in a tree-like format., ls(1): List directory contents.

Copied to clipboard