How to install ncdu on Ubuntu

ncdu is a small command-line program that provides an overview of how your disk space is used. ncdu stands for NCurses Disk Usage, referring to du - a similar built-in utility of Linux. While du only lists the files that eat up most of the storage space, ncdu users can navigate the list using arrow keys and delete files by pressing D key without leaving the application. ncdu is developed and maintained by Yoran Heling.

In this article, we will show you how to install ncdu on Ubuntu. The guide is applicable to older versions of Ubuntu and many as well as Linux distros based on Ubuntu, such as Linux Mint or Pop! OS.

Update the system

Before installing any new package or application, it is recommended that you update your system, GNOME Deksktop is no exception. To do this, run the commands below which invoke apt package manager to fetch a fresh package list from Ubuntu repository.

sudo apt update

Install ncdu

ncdu is available by default on Ubuntu, as well as most of the Debian-based and Ubuntu-based distributions. However, in case you accidentally uninstalled it or your system doesn't have it, you can install ncdu by running the following command.

sudo apt-get install ncdu -y
Code language: JavaScript (javascript)
ncdu running

ncdu examples

Once you had ncdu installed, you can use one of the following commands to analyze your disk space immediately.

Analyze a directory

In order to analyze a directory, simply run ncdu against a path. Remember to replace /dir/ with your desired path.

ncdu /dir/

If you don't specify any path, ncdu will scan the current path by default.

ncdu ncdu 1.16 ~ Use the arrow keys to navigate, press ? for help --- /home/nl ----------------------------------------------- 32.1 GiB [##################] /.environ 29.0 GiB [###############   ] /vm 12.4 GiB [########          ] /.local 5.9 GiB [######            ] /.cache 3.8 GiB [###               ] /Downloads 3.6 GiB [##                ] /.mail 2.9 GiB [##                ] /Projects 2.8 GiB [##                ] /Documents 2.3 GiB [#                 ] /Videos
Code language: PHP (php)

Exclude directories in ncdu

By default, ncdu scans for everything inside the given path, including symbolic links. You can exclude arbitrary files and directories using the --exclude option followed by a pattern.

There are special filesystem in the folders that you want to exclude, too, such as procfs and sysfs. In order to do that, include the flag --exclude-kernfs into the command.

ncdu --exclude ".environ" --exclude-kernfs 19.0 GiB [##################] /vm 10.0 GiB [#########         ] /.local 7.9 GiB [#######           ] /.cache 3.8 GiB [###               ] /Downloads
Code language: PHP (php)

If manually excluding a long list of files and directories takes too much time, you can include all of them in a text file and pass it onto ncdu along with --exclude-from option.

ncdu --exclude-from exclusion.txt /home/nl 10.0 GiB [#########       ] /.local 7.9 GiB [#######           ] /.cache 3.8 GiB [###               ] /Downloads
Code language: PHP (php)

ncdu on a remote server

By default, ncdu will update the rescan the specified path ten times every second. If you are analyzing disk usage on a remote server, this may be too quick and would cause lags in a SSH connection. Fortunately, there is -q option that can reduce this update interval to 2 seconds.

ncdu -q

If you want to export the result of a scan to a text file for review, simply use the following command:

ncdu -1xo- /usr | gzip > export.gz

This command will scan and analyze the /usr directory, then save the analysis results to the export.gz archive.

You can also review it using the following command.

zcat export.gz | ncdu -f-

Or you can the following command to export results to a directory and access it once the storage analysis is complete.

ncdu -o- | tee export.file | ncdu -f-

In order to analyze a remote server, you can use the following command:

ssh -C [email protected] ncdu -o- / | ncdu -f-

ncdu keyboard shortcut

Here are a few keyboard shortcuts for the ncdu utility.

up, k Move the cursor up
down, j Move the cursor down
right/enter Open selected folder
left, <, h Go back to previous folder
n Sort by name (ascending/descending)
s Sort by size (ascending/descending)
OLD Sort by item (ascending/descending)
d Delete the selected file or folder
t Sort by folder first, file later
g Percentage display or capacity usage graph
a Convert by size of size and disk usage
c Mode switch can count the number of sub-items in the directory
And Hide/show hidden files and executable files
i Display information about the selected item
r Recalculate the current size of the folder
b
q Exit ncdu
v Print out the ncdu version and exit

In order to read more details about ncdu, you can run man ncdu to access ncdu manuals page.

We hope that the information above helped you successfully install and use ncdu to analyze disk space on your Ubuntu system. You may be interested in our other Linux software roundups, including 8 Best Open Source CMDB software, Best Linux Video Converters or Best Python Graphics Libraries. If you have any suggestion, please feel free to leave a comment below.

Click to rate this post!
[Total: 0 Average: 0]

Leave a Comment