Ncdu – Managing Disk Space Using Terminal User Interface

In the world of Linux and Unix-like operating systems, efficiently managing your disk space is crucial. One handy tool that can help you accomplish this task is Ncdu, which stands for “NCurses Disk Usage.” Ncdu provides a Terminal User Interface (TUI) version of the popular du command, allowing you to navigate and manage your disk space effectively. In this blog post, we will explore how to install and use Ncdu to streamline disk space management on your Linux system.

Installing Ncdu

Before we dive into using Ncdu, let’s start by installing it. The installation process may vary slightly depending on your Linux distribution.

Debian/Ubuntu/Linux Mint:

[ajay@legion ~]$ sudo apt-get install ncdu

RHEL, Rocky & AlmaLinux:

If you’re using RHEL, Rocky Linux, or AlmaLinux, you’ll need to enable the EPEL repository and then install Ncdu using yum:

[ajay@legion ~]$ sudo yum install ncdu

Arch Linux/Manjaro:

Arch Linux and Manjaro users can easily install Ncdu via pacman:

[ajay@legion ~]$ sudo pacman -S ncdu

Now that you have Ncdu installed let’s explore how to use it effectively.

How to Use Ncdu

Ncdu is a versatile tool for analyzing disk space. When you run ncdu without specifying any flags or directories, it analyzes the current directory. Here’s a basic example:

[ajay@legion ~]$ cd ~/Pictures
[ajay@legion Pictures]$ ncdu

Upon running this command, you’ll be presented with a user-friendly interface that displays essential information about your disk space usage.

 ncdu interface
figure: its interface
  • The bottom bar provides information on total disk usage, apparent disk size, and the number of items.
  • The top bar offers an option to press ? to access more information about available keybindings.
ncdu's help interface
figure: ncdu’s help interface

Alternatively, you can specify a directory for Ncdu to analyze. For example:

[ajay@legion ~]$ ncdu ~/Downloads

For larger directories, it may take some time to display the results. During this process, you’ll see a “scanning” sub-window to keep you informed.

 ncdu scanning sub-window
figure: ncdu scanning sub-window

Important Keybindings in Ncdu

it supports both intuitive navigation keys and Vim-like keybindings, making it accessible to a wide range of users.

Navigation:

  • up, k: Move the cursor up.
  • down, j: Move the cursor down.
  • right/enter: Open the selected directory.
  • left, <, h: Open the parent directory.
  • q: Quit.

Sort:

  • n: Sort by name (ascending/descending).
  • s: Sort by size (ascending/descending).
  • C: Sort by items (ascending/descending).
  • M: Sort by modification time (-e flag).

Delete:

Press d to delete selected files or directories. Ncdu always asks for confirmation before deletion, preventing accidental data loss.

ncdu delete confirmation
figure: delete confirmation

To prevent accidental data loss, you can use the --disable-delete flag to disable the delete functionality.

  • i: Show information about the currently selected files/directories.
  • r: Recalculate the current directory – useful if you have deleted/created some files from this from some other application/window.
  • b: Open a shell in the current directory, allowing you to execute bash or zsh commands in that directory.
ncdu - pressing ishows file/dir information
figure: ncdu – pressing ishows file/dir information

For other keybindings look at the man page man ncdu

Important Flags in Ncdu

it provides several flags to customize its behavior:

  • --show-hidden, --hide-hidden: Show/hide hidden files. You can toggle this with the e key.
  • --exclude <dir>: Exclude a specific directory from analysis.
  • --color <SCHEME>: Set the color scheme to one of “dark,” “dark-bg,” or “off.” “dark-bg” is a variation of “dark” that works well on light terminal schemes and is the default.
  • --one-file-system: Analyze only the directory within the current file system. This is useful when you have mounted additional file systems (e.g., NTFS partitions) within the directory being analyzed, and you want to focus on the current file system.

For other flags, look at the man page.

You can also place these flags in its configuration file: /etc/ncdu.conf or $HOME/.config/ncdu/config. In this file, lines starting with # are considered comments and are therefore ignored. For example:

# Show hidden files/directories
--show-hidden
# Color scheme
--color dark

Conclusion

Ncdu is a powerful and user-friendly tool for managing disk space in Linux. With its intuitive interface and versatile keybindings, it simplifies the process of exploring disk usage and cleaning up your storage.If you have any questions or suggestions, please feel free to share them in the comments section. And if you’re interested in exploring another disk analysis tool, check out our article on the df command in Linux. Happy disk space management!

Leave a Comment

Your email address will not be published. Required fields are marked *