Analyze Disk Usage in Linux Using Dutree


When managing our Linux systems, one of the most crucial things to consider is how we manage our disk space. Many of us are not aware of this, As we accumulate files and directories on our system, it's easy to lose track of what's taking up space and how to optimize our disk usage. But don't worry, that's where dutree comes in handy!

In this article, we'll look into dutree in detail. We'll cover what it is, how to use it, and what benefits it offers for analyzing disk usage in Linux systems. Whether you're a Linux beginner or an advanced user doesn’t matter, we recommend you to read on and learn how you can use dutree to optimize your disk space usage and keep your system running smoothly from this.

What is Dutree?

Dutree is an important command-line tool that can help us analyze our disk usage and gain insights into our file system hierarchy. With dutree, we can easily see which directories and files are taking up the most space, making it a breeze to clean up our system and optimize our disk usage.

If we talk about how it works, It creates a graphical display of your file system hierarchy that shows how much space each directory and file is using in your Linux system. This tool is especially useful for identifying directories that are taking up too much space, making it easier to clean up your file system and free up storage to optimize the system.

How to use Dutree?

Using dutree is very simple. All you need to do is to install the tool on your Linux system and run it. Here is how to do it −

Step 1: Install Dutree in your System

You can install dutree on your Linux system using your package manager. For example, if you are using Ubuntu, you can run the following command to install it 

$ sudo apt-get install dutree

When you run above command your terminal should generate output look like this −

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
   libncursesw6 libtinfo6
The following NEW packages will be installed:
   dutree libncursesw6 libtinfo6
0 upgraded, 3 newly installed, 0 to remove and 10 not upgraded.
Need to get 103 kB of archives.
After this operation, 346 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 libncursesw6 amd64 6.1-1ubuntu1.18.04 [107 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic/main amd64 libtinfo6 amd64 6.1-1ubuntu1.18.04 [3164 B]
Get:3 http://archive.ubuntu.com/ubuntu bionic/universe amd64 dutree amd64 0.2.11-1 [9188 B]
Fetched 103 kB in 1s (77.1 kB/s)        
Selecting previously unselected package libncursesw6:amd64.
(Reading database ... 160933 files and directories currently installed.)
Preparing to unpack .../libncursesw6_6.1-1ubuntu1.18.04_amd64.deb ...
Unpacking libncursesw6:amd64 (6.1-1ubuntu1.18.04) ...
Selecting previously unselected package libtinfo6:amd64.
Preparing to unpack .../libtinfo6_6.1-1ubuntu1.18.04_amd64.deb ...
Unpacking libtinfo6:amd64 (6.1-1ubuntu1.18.04) ...
Selecting previously unselected package dutree.
Preparing to unpack .../dutree_0.2.11-1_amd64.deb ...
Unpacking dutree (0.2.11-1) ...
Setting up libncursesw6:amd64 (6.1-1ubuntu1.18.04) ...
Setting up libtinfo6:amd64 (6.1-1ubuntu1.18.04) ...
Setting up dutree (0.2.11-1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

Step 2: Run Dutree

Once you have installed dutree, you can run it by typing the following command in your terminal 

$ sudo apt-get install dutree

When you run the dutree command the output will look similar to this −

dutree
.
├── 50.3%   bin
│   ├── 32.1%   npm
│   ├── 7.4%    ls
│   ├── 4.8%    python
│   └── 2.4%    node
├── 35.1%   usr
│   ├── 20.3%   local
│   ├── 11.1%   share
│   └── 3.7%    bin
├── 10.5%   var
│   ├── 8.3%    log
│   ├── 1.6%    lib
│   └── 0.6%    cache
├── 2.6%    etc
└── 1.5%    home
    └── 1.5%    username
        └── 1.5%    Downloads

The shown output displays the disk space usage for each directory and file in the current directory (represented by "."). The percentage shown beside each directory indicates the fraction of disk space occupied by that directory or file in terms of total disk space used. The directories are listed in descending order of disk space usage, so the larger directories are listed first. So you can easily see where most of the disk space is being used and what directories can be configured to improve disk usage.

Benefits of Using Dutree

Dutree offers a few benefits for analyzing disk usage in Linux. Here are some of the major benefits of using the dutree tool −

1. Show the File System Tree

Dutree creates a graphical representation of your file system hierarchy, making it easy to see which folders and files take up the most disk space. This allows you to quickly determine which folders need to be cleared to increase free space on your file system.

2. Supports Aggregating of Small Files

Dutree can aggregate small files into larger ones, making it easy to see which files take up more disk space. This can help you quickly identify which files need to be deleted to free up space on your file system.

3. Allows for Comparing Different Directories

Dutree can compare different directories to see how much disk space each one is using. This can help you identify which directories are taking up the most space on your file system and which ones need to be cleaned up.

4. Supports Excluding of Files or Directories

Dutree allows you to remove specific files or folders from the analysis. This can be useful if you want to delete some files or folders that you do not want to scan.

For example, you can exclude the /home/user directory by running the following command 

$ dutree --exclude /home/user

The command will give the output similar to this −

.
├── usr
│   ├── bin
│   │   ├── ls
│   │   └── grep
│   ├── lib
│   ├── include
│   └── local
├── var
│   ├── log
│   ├── cache
│   └── www
├── bin
├── etc
└── dev

This will exclude the /home/user directory from the analysis and show you the disk usage for all other directories and files on your file system.

Conclusion

In conclusion, dutree is an invaluable tool for managing disk usage on a Linux system. Its graphical representation of the file system hierarchy provides an intuitive view of the storage distribution, which helps you quickly identify areas of inefficiency or bloat. Moreover, dutree's aggregation feature is especially useful for consolidating smaller files that may be scattered across the file system, thus making them easier to locate and remove. Overall, dutree is a highly effective solution for optimizing disk usage on a Linux system. Its user-friendly interface, powerful features, and accurate reporting make it an essential tool for any Linux user looking to manage their storage effectively. If you're seeking a straightforward and dependable solution for managing your disk space, dutree is an excellent choice to consider.

Updated on: 26-Jul-2023

104 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements