How to install and use ncdu for better overview of disk usage in Linux

How to Install and Use Ncdu for Better Overview of Disk Usage in Linux

Spread the love

The default disk usage command from UNIX based system summarizes directories on trees’ sizes, so it includes all their contents and individual files sizes. But, it is helpful to track down space hogs on your system. In other words, it will list directories and files that consume large amounts of space on the hard disk drive.

NCDU explained

Passing the years, ncdu was getting hugely recommended through the internet. NCDU is a disk usage analyzer that has an ncurses interface. However, in this post we’ll explain how to install ncdu on *UNIX-based system to check the disk usage.

Installing NCDU

In order to install NCDU, you’ll have to see what is the Distro that you are using, to use one of the below codes:

1. Debian-based install
– Apt command to install ncdu:

sudo apt install ncdu

2. CentOS/RHEL/Fedora install:
– To install on CentOS/RHEL/Fedora you must enable EPEL repository using this command:

sudo yum install epel-release

– Then you can run the ncdu installation command on CentOS:

sudo yum install ncdu

– Or, if you are running Fedora, you should run:

sudo dnf install ncdu

3. Alpine Linux install:
– You can try to install it using the apk command:

apk add ncdu ncdu-doc

4. OpenSUSE/SUSE Linux:
– For this system, we use zypper:

sudo zypper in ncdu

5. Arch Linux:
– On arch linux, you should use pacman:

pacman -S ncdu

6. FreeBSD unix:
– Type the following command on your terminal:

sudo pkg install ncdu

7. OpenBSD:
– There’s little difference on this one, so just copy below to install it:

doas pkg_add ncdu

How to use NCDU

The syntax of it is really simple, you just need to use as it described below:

ncdu
ncdu <flags> <directories>

Flags and the directory are optional, if not provided, the command will check your current working directory. When you run the command, the disk usage of each directory from your current one will show up as a list. To exit that list, you can simply press “Q”.

You can get info from any directory using NCDU, simply use:

ncdu /root
ncdu /home
ncdu /var/log

NCDU flags

In that section we’ll review some flags available to be used on the NCDU command. The first one is the flag “-x”.

This flag let you scan a full system, your root filesystem. To use it, you can run:

ncdu -x /

We can also enable the extended information mode with the flag -e, simply run:

ncdu -e

If you want your ncdu response to having some colors, you can add this by using the “–color” flag:

ncdu --color dark -x /

We can also exclude files that match the provided pattern:

ncdu --exclude '.ht*'
ncdu -x --exclude '/var/log/ --exclude '/directory2' --exlucde ... /

There are many others and shortcuts that are explained in their manual:

man ncdu

That’s it. You have successfully installed NCDU on Linux and learned its basic syntax. You can now use it on your system to have a better usage description on your server.

Leave a Reply

Your email address will not be published.