Ncdu

The name Ncdu stands for “NCurses Disk Usage”, clearly named after “ncurses”, which was short for “new curses” because it was an update was an update of a code library called “curses”. Some programs use the “curses” library, or more commonly the updated variation named “ncurses”, to control details of a text console, including where the cursor is positioned. These effectively lets a program easily re-draw a text console.

Michael Mrozek's question to ripper234's Unix.StackExchange.com question, “How to understand what's taking up disk space?” included a screenshot of Ncdu (surrounded by a GUI window).

Usage Notes

A simple way to run the program is without any parameters. After the program is installed, simply run “ncdu”.

The following example shows a more elaborate way to run the program. A copy of the data is saved (in the /tmp/ncducopy.gz file) so if there is a need/desire to end the program, the data file can be used. Although the data file might be slightly out of date, it may be much faster than re-reading all of the relevant details from the hard drive.

sh -c "ncdu -e -o- / | gzip -9" | tee /tmp/ncducopy.gz | gzip -dc | ncdu -2 -e --color dark -f-

The following example shows a more elaborate way to run the program, using networking. This may be helpful to use ncdu to gather data from a remote system, but then use ncdu on a local system to view results. A copy of the data is saved (in the /tmp/ncducopy.gz file) so if there is a need/desire to end the program on the local machine, the data doesn't need to be re-gathered from the remote machine.

This can be quite nice if the remote system is using an old version of ncdu which cannot be upgraded very easily. The local version of ncdu is used for viewing the data, so the data can be viewed by any machine with ncdu (which may be able to easily run a newer version of ncdu).

A “remote host” (which could be IPv6::1” or IPv4127.0.0.1”.)

ssh -C -l loginName remote.example.org "ncdu -e -o- / | gzip -9" | tee /tmp/ncducopy.gz | gzip -dc | ncdu -2 -e --color dark -f-

The above sample is slightly genericized. A more specific example is shown below.

Using the above approach allows for one copy of the program to gather data on a machine, without using a lot of resources to have that machine's memory store data about details found on the filesystem. That data gets compressed and then sent over network to a receiving computer. The receiving computer performs the entirely optional step of using tee to store a copy of the received compressed data to a file (named /tmp/ncducopy.gz), and then the receiving computer can interact without any need to keep using network bandwidth, nor to keep using any resources on the remote computer's end.

The above example stores the data on the local computer running the SSH client. If you wanted the data stored on the computer running the SSH server (which may make sense considering that the data is about that server), move the second quotation mark to just after the “/tmp/ncducopy.gz”.

Those are the upsides to the approach of using a network. The downside is that the program doesn't have an easy way to just refresh its data by re-reading the disk when the program is using imported data. Also, while the user has the ability to check out the contents of a specific location, the user loses the interactive ability to just press the b key to easily start a shell from a specified location.

To use networking to simulate connecting to a remote machine, but using the local machine, the following sample may work. This sample also performs the optional step of using tee to keep a copy of the gathered information, and specifies to just look at the /usr/ directory.

ssh -C -l $(id -nu) localhost "ncdu -e -o- /usr/ | gzip -9" | tee /tmp/ncducopy.gz | gzip -dc | env COLUMNS=72 ncdu -2 -e --color dark --confirm-quit -f-

ncdu in PuTTY

(These notes are likely to move, and be replaced here by a hyperlink to the location which is more about PuTTY and not just ncdu...) The line art may look like a bit less than perfect. For instance, instead of looking like a nice vertical line, the characters may show up as a lowercase a with a circumflex (“â”).

The newer way to remedy that, using PuTTY 0.71 or newer, is to go to the Window options, Translation screen, and check the box that says “.....”. https://serverfault.com/a/818876/262387 https://superuser.com/a/278337/401839 It also may help to use UTF-8, and to run programs with the following environment variable set: export NCURSES_NO_UTF8_ACS=1 (documentation here is unfinished....) To remedy Windows\Translation ISO-8859-1:1998 (Latin-1, West Europe)

Sample Output

Sample output, after pressing g twice (which inserted space for seven characters before the hash marks, showing percentages), and c to show the column just before the directory names, which is the count of sub-items. (The periods are simply separators, like how Americans typically use commas.)

ncdu 1.13 ~ Use the arrow keys to navigate, press ? for help  [imported]
--- /usr ---------------------------------------------------------------
  291.2 MiB [ 25.0% ##########] 16.813 /local                                          
  270.3 MiB [ 23.2% ######### ] 10.028 /share
  198.9 MiB [ 17.1% ######    ]    219 /lib
  177.7 MiB [ 15.3% ######    ]  9.527 /X11R6
  128.2 MiB [ 11.0% ####      ]    334 /bin
   45.9 MiB [  3.9% #         ]  1.963 /libdata
.  43.0 MiB [  3.7% #         ]     53 /libexec
   26.2 MiB [  2.2%           ]  2.264 /include
   20.2 MiB [  1.7%           ]    203 /sbin
    1.9 MiB [  0.2%           ]     45 /games
  548.0 KiB [  0.0%           ]      9 /mdec
!   2.0 KiB [  0.0%           ]        /xobj
e   2.0 KiB [  0.0%           ]        /src
!   2.0 KiB [  0.0%           ]        /obj







 Total disk usage:   1.1 GiB  Apparent size:   1.1 GiB  Items: 41472

Unlike some older traditional Linux programs like du or find, this program is interactive. So, a person can press ? to receive online help, down arrow to select a different directory, Enter to go into directory and see a similar view of just the contents of that directory, or q to quit this interactive program.

This guide recommends starting out by pressing g a couple of times to show both the numeric percentages and the hash mark displays. Pressing i will show more details.

ncdu 1.13 ~ Use the arrow keys to navigate, press ? for help  [imported]
--- /usr/local ---------------------------------------------------------
                                /..
  130.3 MiB [ 44.8% ##########] /include
  119.5 MiB [ 41.0% ######### ] /lib
   22.9 MiB [  7.8% #         ] /share
   11.5 MiB [  3.9%           ] /bin                                              
    4.┌―――Item info―――――――――――――――――――――――――――――――――――――――――――――┐
    1.│                                                         │
  544.│  Name: bin                                              │
  392.│  Path: /usr/local                                       │
   52.│  Mode: drwxr-xr-x  UID: 0      GID: 0                   │
      │  Last modified: YYYY-MM-DD hh:mm:ss -ZZ00               │
      │     Disk usage:  11.5 MiB (12.017.664 B)                │
      │  Apparent size:  10.9 MiB (11.471.059 B)                │
      │                                                         │
      │                             Press i to hide this window │
      └―――――――――――――――――――――――――――――――――――――――――――――――――――――――――┘





 Total disk usage:   1.1 GiB  Apparent size:   1.1 GiB  Items: 41472

Interestingly, a period seems to be used as the numeric group separator when the “MiB” are converted to bytes, although the period is also used as a decimal point when showing the amount of megabytes and percentages. So the program seems to be showing items with a hybrid of localization methods that, inconsistently, doesn't fully match any single territory.

Here is a sample of the screen that shows the dialog box that is enabled by using “--confirm-quit” option. Also, this shows a sample of the output like how the program initially shows up, not showing the percentages.

ncdu 1.13 ~ Use the arrow keys to navigate, press ? for help  [imported]
--- /usr/local ---------------------------------------------------------
                         /..
  130.3 MiB [##########] /include
  119.5 MiB [######### ] /lib
   22.9 MiB [#         ] /share
   11.5 MiB [          ] /bin
    4.9 MiB [          ] /man                                                 
    1.1 MiB [          ] /sbin
  544.0 KiB [          ] /sbin
  392.0 KiB [        ┌―――ncdu confirm quit――――――――┐
   52.0 KiB [        │                            │
   52.0 KiB [        │ Really quit? (y/N)         │
                     └――――――――――――――――――――――――――――┘











 Total disk usage:   1.1 GiB  Apparent size:   1.1 GiB  Items: 41472

Installation Notes

Note: For CentOS / Fedora systems, ComputingForGeeks.com: ncdu - Analyze Disk usage in Linux with ncdu notes “the package is available from EPEL repository”. FedoraProject.org EPEL FAQ identifies EPEL as “Extra Packages for Enterprise Linuxrdquo;, “a volunteer-based community effort from the Fedora project to create a repository of high-quality add-on packages that complement the Fedora-based Red Hat Enterprise Linux (RHEL) and its compatible spinoffs, such as CentOS.” “EPEL packages are 100% free/libre open source software (FLOSS).”

The following commands are based on advice provided by the ComputingForGeeks.com: ncdu - Analyze Disk usage in Linux with ncdu page, as well as mixing in Some detail from information found on ripper234's question on Unix.StackExchange.com titled “ncdu.

Try these commands:

sudo yum -vty install epel-release
sudo yum provides ncdu # This seems entirely optional

Then (if not using Fedora... and maybe also if using Fedora?)...

sudo yum --enablerepo=epel -vt install ncdu

If not using Fedora...

sudo dnf install ncdu