Linux ncdu Command: Interactive Disk Usage Analyzer

The ncdu (NCurses Disk Usage) command is a lightweight, terminal-based utility designed to analyze disk space utilization on Linux systems. Serving as an interactive alternative to the standard du command, it combines fast scanning capabilities with an intuitive ncurses text-based user interface. This article explores how ncdu functions, how to install and navigate it, and how to use its core features to identify and clean up large files directly from the command line.

What is the ncdu Command?

On Linux, locating directories consuming excessive storage traditionally requires chaining commands like du -sh * | sort -h. While effective, this process is static and slow for deep directory hierarchies.

The ncdu command solves this problem by performing a recursive scan of a specified directory and displaying the results in an interactive, scrollable list. It presents directory sizes visually using progress bars and absolute values, enabling system administrators to quickly pinpoint disk hogs and manage files without leaving the terminal.

Installing ncdu

Because ncdu is not typically installed by default, you must install it using your distribution's package manager:

Basic Usage

To analyze the current working directory, run:

ncdu

To scan a specific path, provide the target directory as an argument:

ncdu /var/log

To scan the entire root filesystem without crossing into other mounted filesystems (such as network shares or external drives), use the -x flag:

sudo ncdu -x /

Running the command with sudo ensures that ncdu can read system directories protected by root permissions.

Once the scan completes, ncdu provides an interactive browser. You can navigate through your filesystem using standard key bindings:

Advanced Features

The ncdu command is a vital tool for Linux disk management, eliminating the complexity of manual pipeline scripts and offering immediate visual clarity over storage consumption.