Linux Tactic

Master Disk Space Management with Ncdu on Linux

As data continues to pile up on our computers, finding and managing disk space becomes increasingly important. That’s where ncdu comes in handy.

Ncdu is a disk usage analyzer for Linux that enables you to identify space hogs on your server or local machine. With its Terminal User Interface (TUI), it provides a straightforward way to view directories and determine which files are taking up the most space.

In this article, we’ll cover how to install and use ncdu on Linux, and how to navigate its various menus and features. Whether you’re a seasoned developer, sysadmin, or just starting with Linux, understanding how ncdu works will save you valuable time and frustration.

Installing ncdu

Before we begin using ncdu, we need to install it. Luckily, installation is a breeze on Linux systems.

On Ubuntu, you can install ncdu using the following command:


sudo apt-get install ncdu


This command installs ncdu and all its dependencies. Once installed, you can start using it immediately.

Using ncdu

Now that we have ncdu installed, let’s explore its features. The command to start ncdu is simply `ncdu`.

Running this command will present you with a TUI showing the disk usage of your current directory.

Navigating the directory tree

Use the arrow keys to navigate the directory tree. Directories are displayed with blue text, with files displayed in white.

You can sort directories by size with the “S” key.

Selecting a directory

To select a directory, move the cursor to it using the arrow keys and press Enter. This will display the disk usage for that directory, including its subdirectories.

Viewing directory information

Once you’ve navigated to a directory, ncdu will provide a list of files and directories, sorted by size. You can view more detailed information about a file or directory by highlighting it and pressing the “i” key.

This will display the full path to the directory or file, as well as its size, permissions, and owner.

Deleting files

If you find a file that you no longer need, you can delete it directly from ncdu by highlighting it and pressing the “d” key. This will prompt you to confirm that you want to delete the file before it is permanently erased.

Be careful when deleting files from the command line, as there is no way to recover them once they are deleted.

Opening Help window

If you need help while using ncdu, you can press the “?” key to open the Help window. This will display a list of keyboard shortcuts and other useful information.


Ncdu is an essential tool for managing disk usage on Linux systems. Its TUI provides an easy way to navigate directories and identify space-hogging files and folders.

We hope this article has been helpful in explaining how to use ncdu and its various features. With a little practice, you’ll be able to manage disk space on your Linux system with ease.

Remember to be cautious when deleting files from the command line, and always confirm before permanently deleting them. Happy disk space management!

3) Deleting a Directory

In addition to identifying large files and directories, ncdu also provides us with the ability to delete them directly from the TUI interface. However, deleting a directory with ncdu requires special care, as it is irreversible.

Before you delete a directory, ensure that you have backed up any important files and data.

To delete a directory with ncdu, first navigate to the directory you wish to delete by using the arrow keys.

Once you have selected the directory you wish to delete, press the “d” key to prompt a confirmation prompt. Press “y” to confirm the deletion or “n” to cancel.

Once you have confirmed the deletion, ncdu will remove the directory and all of its contents permanently. If you need to delete a large number of files or directories, it might be quicker to use the command-line.

To delete a directory with all its files and subdirectories using the command-line, run the following command:


rm -rf /path/to/directory


This command will delete the specified directory and all of its contents without prompting for confirmation. Be extremely careful when using this command, as it is very powerful and can cause permanent damage if used incorrectly.

4) Scanning and Exporting Results

By default, ncdu scans the current working directory for size information. However, you can use the ncdu command with specific paths or directories to scan only those directories, saving time and improving performance.

This is especially useful if you have a large number of directories that you need to scan for large files. To scan a specific path or folder, use the following command:


ncdu /path/to/directory


This command will scan the directory you specified and display the disk usage for each directory and file within it.

You can then navigate through the various subdirectories as you normally would with the TUI interface. While scanning a large directory can take some time, exporting the results once the scan is complete takes less time.

Ncdu allows you to export the results of a scan to an archive file, which you can then use for future reference or to analyze disk usage data at a later point in time. To scan the entire system and export the results to an archive file, use the following command:


sudo ncdu -1xo- / | gzip > /path/to/archive.tar.gz


This command will scan the entire root system and export the results to an archive file located at the specified path.

The -1xo- flag specifies that ncdu should output results in a format that can be exported to an archive file, while the -x flag instructs the command to stay on one file system. Once the scan is complete, the output is piped to the gzip command, which compresses the data and saves it to the archive file specified.

This archive file can then be transferred to another system or analyzed at a later point in time using ncdu.


Ncdu is a powerful tool for analyzing disk usage and identifying space-hogging files and directories. Understanding how to use it to scan and delete directories can save you a lot of time and frustration.

Remember to always be careful when deleting files and directories, and to back up important data before making any significant changes to your system. The ability to scan specific directories and export results is extremely useful for analyzing disk usage trends over time and making informed decisions about resource allocation.

With ncdu, managing disk space on Linux systems couldn’t be easier.

5) ncdu Colors and Shortcuts

One of the great features of ncdu is its ability to display colors for different types of files and directories. This makes it easier to distinguish between file types and quickly identify space-hogging directories.

To enable color output in ncdu, simply add the -C option to the command-line when running ncdu:


ncdu -C /


This will enable color output for ncdu, making it easier to navigate and identify files and directories. Different types of files will be shown in different colors, such as directories in blue, regular files in white, and symbolic links in pink.

Navigating ncdu output is made easier with keyboard shortcuts. Here are some of the most useful ncdu keyboard shortcuts:

– “q”: quits ncdu and exits to the command line.

– “h”: opens the help screen, displaying a list of all the keyboard shortcuts in ncdu. – “u”: moves up one directory level.

– “r”: refreshes the current screen with the latest data. – “s”: sorts the current directory listing by size.

– “d”: deletes the currently selected file or directory. – “i”: displays detailed information about the currently selected file or directory.

– “g”: displays the grand total size for the current directory and all subdirectories. These shortcuts are designed to make navigating ncdu quick and easy, and with a bit of practice, they can save you a lot of time.



Using ncdu is a great way to gain insight into your disk usage and identify space-hogging files and directories. Compared to the regular “du -h” command, ncdu provides much clearer and more concise output, making it easier to navigate and understand.

With ncdu, you can quickly navigate through directories, view detailed information about files and directories, and delete files directly from the TUI interface. By using keyboard shortcuts and enabling color output, you can further improve your experience with ncdu and make disk usage analysis even easier.

With knowledge of these features and shortcuts, you’ll be able to use ncdu to actively manage your disk usage and keep your system running efficiently. Overall, the advantages of using ncdu are clear.

With its intuitive interface and numerous options and commands, it provides a powerful utility for managing disk usage on Linux systems. Whether you’re a sysadmin managing a server or a developer working on your own machine, ncdu is an essential tool for keeping your system running optimally.

In conclusion, ncdu is a powerful utility for managing disk usage on Linux systems. It provides an intuitive interface, numerous options and commands, and features like color output and keyboard shortcuts that make it easier to navigate and analyze disk usage.

By using ncdu, you can quickly identify space-hogging files and directories, delete them, and gain valuable insights into disk usage trends over time. Whether you’re a sysadmin or a developer, ncdu is an essential tool for keeping your system running optimally.

With knowledge of its features and shortcuts, you can increase your efficiency and productivity in managing disk space.

Popular Posts