How to Use ncdu to Check Disk Space in Linux?

The “ncdu” stands for “NCurses Disk Usage” utility that provides the easiest and most reliable way to check the system disk details. It contains a text-based interface that acts as a disk analyzer. It assists the user in navigating to the directory and discovering each subdirectory disk space. The “ncdu” offers the shortcut keys to navigate the list of directories and removes the extra files/directories that take up too much space.

This post illustrates the working of ncdu to check the disk space in Linux.

  • Prerequisites: Install ncdu in Linux
  • Using ncdu in Linux
  • Check Current Directory Usage
  • Display the Subdirectory Details
  • Navigate to the Particular Subdirectory
  • Particular Directory Disk Usage Details
  • Get Root Directory Disk Usage

Prerequisites: Install ncdu in Linux

The “ncdu” is the external utility so first install it in your Linux system by following the stated steps:

Step 1: Install ncdu Tool

The “ncdu” command installation files are present in the default repositories of all the Linux distributions. Use the default package manager to install it as per Linux distribution:

$ sudo yum install ncdu                         # For RHEL/CentOS
$ sudo dnf install ncdu                         # For Fedora
$ sudo pacman -S ncdu                           # For Arch Linux
$ sudo apt install ncdu                         # For Ubuntu/Debian

The “ncdu” package has been installed along with dependencies.

Step 2: Verify ncdu

Execute the “-version” argument to check the version of the “ncdu” utility:

$ ncdu -version

The installed “ncdu” version is “1.15.1” in the system.

How to Use Ncdu to Check Disk Space in Linux?

The “ncdu” command line tool is beneficial for getting the disk usage detail of the current or specific directory. This section explains its unlimited usage with the help of practical implementation:

Check Current Directory Usage

The “ncdu” command, without passing any argument, opens up the disk usage details of the current directory:

$ ncdu

The output contains the disk usage of the current “/home” directory that is “94.1 MiB” having “522” items. Press “q” to quit the ncdu window.

Display the Subdirectory Details

The “ncdu” command line interface supports the keyboard arrow keys “up” and “down” to navigate in the “ncdu” interface.

Use the “i” key to check the subdirectory disk usage detail of the opened directory. It pops up the “Item info” dialogue box:

The output shows the “Videos” directory disk usage detail, i.e., “4KiB,” and also some other useful information. Press “i” to quit this window.

Navigate to the Particular Subdirectory

Move to the specified subdirectory and press the “right-arrow” key to open it. For instance, the “.local” subdirectory is accessed as below:

The “.local” directory occupies “772.0” KiB of the disk. Press the “left-arrow” key to move back to the initial directory.

Particular Directory Disk Usage Details

Specify the name or the absolute path of the particular directory, such as “Documents,” with the “ncdu” command to check its disk usage detail:

$ ncdu ~/Documents

The output shows the Total disk usage size of the “Documents” directory having “3” items in it, i.e., subdirectories.

Get Root Directory Disk Usage

To scan the disk usage of the “root” directory, use the forward-slash(/) with the “-x” option of “ncdu”:

$ sudo ncdu -x /

The scanning of the “root” directory is being started it takes few seconds to complete the process:

The root directory occupies “9.8 GiB” disk space having “216841” items.

Conclusion

Linux offers the “ncdu” command without any argument to check disk space usage. However, it is an external command line utility and can be installed easily from local repositories. Its command line interface allows the arrow keys to navigate into it and access the particular directory.

This post has explained the working of the ncdu command to check the disk space in Linux.