dutree – A CLI Tool to Analyze Disk Usage in Coloured Output


The dutree is an open-source and free command line tool in Linux that lets you analyze disk usage and display the output in a colored format. This command combines two well-known Linux commands, the durep (generates disk usage report) and the tree (lists the contents of a directory in tree format) commands, and their attributes, written in the Rust language. Whenever you use this command to determine disk usage, it displays the result in a tree-like format.

The dutree command is mainly used to see which directories and files take up the most space on the hard disk and lists those files and directories. This allows you to control these files and free up disk space.

So if you are looking for ways to use the dutree to analyze disk usage, this tutorial is just for you. Here, we will install and use the dutree command in Linux.

How to Install dutree On Linux

The dutree command is written in Rust language, so it is necessary to have this language utility in your system before installing dutree. To install the Rust language, run the following command in the terminal:

:~$ sudo curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

After installing Rust, you can install dutree through the following command:

:~$ sudo cargo install --git https://github.com/nachoparker/dutree.git
:~$ sudo apt install cargo

Note: Before using the above command, ensure your system has git, cargo, and curl utilities.

Once you install dutree, you can check the colors of the environment in the system according to the variable LS_COLORS. Similar to the ls --color command, it contains the colors our distro configures.

:~$ ls --color

dutree displays colored output based on the values configured in the GNU ls --colors environment variable. Depending on the file permissions, type, and extension, this env variable enables setting the colors. Running dutree without any arguments displays a filesystem tree as follows:

:~$ dutree

This result varies depending on the directory you are located in. You can use the -u parameter to see actual hard disk usage instead of file size.

:~$ dutree -u

By default, dutree prints the output in kilobytes. You can print the result in bytes using the -b option.

:~$ dutree -b

You can display only ASCII characters and turn off the colors using the -A option.

:~$ dutree -A

Options of dutree Command

In this section, we will explain different ways to use dutree command in various scenarios:

Exclude Hidden Files

There are always some hidden files in your system that take much time to scan. These hidden files do not negatively impact the overall system stability. So you can exclude these hidden files while finding the hard disk usage. You can use the -H flag with the dutree to exclude hidden files.

:~$ dutree -H

Add Minimal Files

By default, dutree shows a file size of 1M; with the help of dutree, you can see even smaller files using the -a flag.

:~$ dutree -a

Exclude Directories and Files from the Output

You can exclude any specific folders and directories from dutree analysis results. You must append the filename or folder you want to exclude to dutree using the -x flag.

:~$ dutree -x <directory / file name>

You can use the -x flag to exclude the matching directory name:

:~$ dutree -x CentOS-7.0-1406-x86_64-DVD.iso

Similarly, you can have a quick local overview by removing directories using the -f option.

:~$ dutree -f

Also, using the -s flag, you can display a full overview/summary.

:~$ dutree -s

Display Directories in Depth

Using the dutree command, you can display directories up to a specific depth. By default, it shows directories or folders up to depth 1, which you can fix according to your requirement using the -d flag.

For example, if you want to see directories up to depth 3, you can run the dutree command with the -d option as follows:

:~$ dutree -d 3

Note: Make sure you are in the directory you want to find the disk usage for a specific depth.

You can explore the additional dutree information using the -h option.

:~$ dutree -h

Conclusion

Through the dutree command line utility, you can manage and fully control the disk usage of hard drives in Linux. It lets you analyze disk usage, explore file space in a tree-like format, and print the colored output. Excluding hidden files, deleting specific files and directories, viewing details of directories up to a specific depth, etc., are some of its features. Using these features, you can compare the files and directories.

Apart from all these advantages, one is that it focuses on and shows routes that occupy more space rather than displaying only the root of files with their details and size.

Updated on: 13-Sep-2023

97 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements