Ncdu, the treesize for Linux

From EN Ikoula wiki
⧼vector-jumptonavigation⧽ ⧼vector-jumptosearch⧽

en:Ncdu, the treesize for Linux fr:Ncdu, le treesize pour Linux


Introduction

NCDU means for NCurses Disk Usage.

Ncdu is a simple and fast disk usage analyzer that is used to find directories or files that take up the most space on a local or a remote system.
It will allow you to easily move from one directory to another using the cursor keys and even take actions on files such as deleting or moving folders.

Installation

Debian, Ubuntu :

$ sudo apt install ncdu

CentOS, AlmaLinux, Rocky Linux:

$ sudo dnf install ncdu
In old system besed in RHEL, you can use yum:
$ sudo yum install ncdu

Utilisation

Once installed, you just need to run the command :

$ ncdu

Ncdu-1-ENG.PNG


For information, the ncdu when it is launched will read the directory in which you are, you can however indicate the directory that you wish.

  • Exemples:

ncdu /
ncdu /home
ncdu /var/log

Save results to a file

Sometimes you may want to save your analysis report and view it later. In this case, scan the directory you wish and export the results in any archive format for later consulting, as below. >br> For exemple as a file gzip

ncdu -1xo- / | gzip >rapport.gz

This command will scan the / directory and save the scan report in a file called report.gz.

You can consult it later by running the following command:

$ zcat rapport.gz | ncdu -f-

Analysis of disk usage in a remote system

$ ssh -C root@192.168.1.250 ncdu -o- / | ncdu -f-

Lexicon:

  • root: User of the remote system.
  • 192.168.1.250: @IP of the remote machine.
  • -C: Enable compression.

To exit ncdu, press q.

==List of options for the ncdu utility==.

  • Up, k - Move cursor up.
  • Down, j - Move cursor down.
  • Right arrow, ENTER key - Open the selected directory.
  • Left arrow, <, h - Open the parent directory.
  • n - Sort by name (ascending/descending).
  • s - Sort by size (ascending/decreasing).
  • C - Sort by items (ascending/descending).
  • d - Delete the selected file or directory.
  • t - Toggle directories before files when sorting.
  • g - Display the percentage and/or the graph.
  • a - Toggle between apparent size and disk usage.
  • c - Toggle display of the number of child items.
  • e - Show/hide hidden or excluded files.
  • i - Show information about the selected item.
  • r - Recalculates the current directory.
  • b - Launch the shell in the current directory.
  • q - Exit ncdu.



For more details, consult the manual.

$ man ncdu

Conclusion

Now you know how to analyze the disk usage with Ncdu. Ncdu is a powerful and fast utility that allows you to check which directories occupy the most space in your system.

From your analysis, you can find a directory or file that consumes space on your hard disk. You can delete it or move it safely to another disk to free up disk space.



Did you find this article useful?

0


You are not allowed to post comments.