FOSS, linux, OYB software, rust, shell

Analize disk usage with dutree

dutree is a command line tool to analyze disk usage.

Features

  • coloured output, according to the LS_COLORS  environment variable.
  • display the file system tree
  • ability to aggregate small files
  • ability to exclude files or directories
  • ability to compare different directories
  • fast, written in Rust

This tool is a mix between tree and durep, which we already used in this other post.

Installation

Usage

dutree will use the environment colors as configured in the variable LS_COLORS. This means that will match the colors of commands such as ls --color that you or your distro have configured.

You can see more details about this variable here.

Examples

Depth

If you just want to have a quick overview, use the -s  flag.

, or you can just look at the first directory depth

, and increase detail if needed

, or just show everything

Skip directories

If you are only interested in the files in the current folder, you can have a quick view.

Aggregate

You can aggregate small files under a certain file size for better visualization.

The default is one mebibyte.

 

Exclude

You can exclude any number of directory or file names

 

Compare

You can compare any number of different folders, for instance these snapshots taken on different dates with btrfs-snp.

Disk usage

The file size of files is not actually equivalent to the disk usage, this is, the real amount of disk blocks that are used. Small files will take up more space than we might assume because only one small file will be stored in one block. See this post for a more complete explanation.

In fact, all files in disk are rounded to the block size, 4 kibibytes in this example.

Also, there are files that are sparse in modern filesystems. This means that they don’t use all the blocks that they need to, because for instance they have big sections of zeroes and the filesystem is smart enough to optimize that. Pay attention to the file_sparse in this example: it doesn’t really use 8KiB of disk blocks, but the minimum of 4KiB.

ASCII output

If you don’t care about fancy colors or you have problems with block characters in your old terminal, you can get the output in good old plain ASCII characters.

Another option is to unset the LS_COLORS  variable.

Author: nachoparker

Humbly sharing things that I find useful [ github dockerhub ]

6 Comments on “Analize disk usage with dutree

  1. Nacho when I’ve tried to install using your instructions I get
    warning: be sure to add /home/tim/.cargo/bin to your PATH to be able to run the installed binaries
    at the of installation and if I use the command dutree I get command not found. Any ideas

    1. If you have never installed anything before with cargo, you need to add at the end of your ~/.bashrc the following line

      export PATH="/home/tim/.cargo/bin:$PATH"

      Then dutree will be available next time you open a bash shell

Leave a Reply

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