Home » Linux Host, Ubuntu, SysAdmin » Efficiently Analyze Directory Sizes in Linux Using ncdu

Efficiently Analyze Directory Sizes in Linux Using ncdu

The ncdu (NCurses Disk Usage) command is a fast and user-friendly tool to analyze disk space usage in Linux. Unlike the traditional du command, ncdu provides a text-based interface for easier navigation of directory sizes.

Step 1: Installing ncdu

Before using ncdu, you need to install it. Run the following command:

sudo apt install ncdu  # For Debian/Ubuntu systems

For other distributions, replace apt with your package manager, like yum for RedHat-based systems.

Step 2: Running ncdu

To identify the total size of individual directories, simply run:

ncdu /path/to/directory

For example, if you want to analyze your home directory:

ncdu /home/user

Once it runs, you’ll see a navigable interface listing directories and their respective sizes. The largest directories will be listed first, making it easy to see which folders consume the most disk space.

Step 3: Navigating the Interface

  • Arrow keys: Use the up and down arrow keys to navigate between directories.
  • Enter: Press “Enter” to drill down into subdirectories.
  • d key: If you want to delete a large directory directly from ncdu, press “d.”

Step 4: Filtering Results

If you want to exclude certain files or directories, you can use flags. For instance:

ncdu --exclude /proc /path/to/directory

This command will analyze the directory while excluding the /proc folder.

Example:

To analyze your root directory (/):

sudo ncdu /

This will show all directories and their sizes on your system.

ncdu

Leave a Comment