Linux ncdu terminal disk visualization tool

The full name of ncdu is NCurses Disk Usage. It is similar to the du command, ncdu will be more friendly and easy to use than the du command

3 min read
By myfreax
Linux ncdu terminal disk visualization tool
Linux ncdu terminal disk visualization tool

The full name of ncdu is NCurses Disk Usage. It is similar to the du command, ncdu will be more friendly and easy to use than the du command, but without the high degree of customization of the du command.

Many Linux distribution desktop environments now come with disk visualizer tools, these are common solutions for finding large files in GUI desktop environments.

In this tutorial, we will explain how to search or find large files using ncdu in Linux. It is a disk usage visualizer for Terminal.

install ncdu

The ncdu command is not pre-installed on most Linux distributions. To check if the system has ncdu installed. Please press the shortcut key CTRL+ALT+Tto open the terminal and run the command ncdu.

If your Linux system does not have ncdu installed, the terminal will print the error message command not found: ncdu.

If your computer is running a Debian-based Linux distribution. Such as Linux mint, Ubuntu. Please run the command to sudo apt install ncdu install ncdu.

If your computer is running a RedHat-based Linux distribution. For example CentOS, Fedora. Please run the command to sudo yum install ncdu install ncdu.

sudo apt install ncdu
sudo yum install ncdu

ncdu command

Before introducing how to use the ncdu command, let us first understand the basic syntax. The syntax of the ncdu command is ncdu <options> <directory>.

options Options for the command, optional arguments. directory is a directory, which can be a relative path or an absolute path.

When running the ncdu command without specifying any parameters and options, the ncdu command will scan the size of the current directory and display the size of each file directory.

ncdu Command Options

There are not many options for the ncdu command, here are just a few commonly used options. The first is the -o option to export the scan results of the ncdu command to a file in JSON format. The -f option imports from a file into ncdu.

The -L / --follow-symlinks option, as the name suggests, follows symbolic links, but ncdu does not follow symbolic links of directories.

The -r option means to start ncdu in read-only mode. That is to say, it can only be viewed, but cannot be deleted in ncdu. For important files, misoperation can be avoided.

The option --exclude of the ncdu command allows you to exclude directories of files, and the --exclude option allows you to use pattern matching to exclude directories.

ncdu shortcut key

ncdu allows you to use shortcut keys to switch directories, and you can use the keyboard arrow keys or the j and k keys to select files up and down.

h Go back to the parent directory and enter the subdirectory with the l key . Press ? for help. n Sort by name, sort s by size, sort Cby number of directory files.

M Sort by mtime, which is the modification time of the file. q Exit ncdu or exit help instructions, and d delete the selected files.

ncdu sort files by size

To sort files by size in ncdu, press the shortcut key s to sort by size in ascending or descending order.

ncdu sorts files by modification time

To sort files by size in ncdu, please press the shortcut key M, you can sort by the modified ascending or descending order.

ncdu delete file directory

To delete a file directory in ncdu, you can use the keyboard arrow keys or the j and k keys to select the file and directory to be deleted.

When selecting the file directory to be deleted, please press the d key to delete, ncdu will ask you whether to delete the file directory, select yes to delete the file, no to not delete the file.

If you choose "don't ask me again", the file will also be deleted, and don't ask me again means no longer asking. This no longer asking is only valid in the current session. Reopening ncdu will ask again.

ncdu delete file

Conclusion

So far, you have learned how to use ncdu to search or find large files in the Linux terminal. ncdu is a terminal disk visualization tool. Feel free to leave a comment if you have any questions.