Replace du with dust on Linux

The dust command is a more intuitive implementation of the du command written in Rust.
52 readers like this.

If you work on the Linux command line, you will be familiar with the du command. Knowing commands like du, which returns information about disk usage quickly, is one of the ways the command line makes programmers more productive. Yet if you're looking for a way to save even more time and make your life even easier, take a look at dust, which is du rewritten in Rust with more intuitiveness.

In short, dust is a tool that provides a file's type and metadata. If you trigger dust in a directory, it will report that directory's disk utilization in a couple of ways. It provides a very informative graph that tells you which folder is using the most disk space. If there is a nested folder, you can see the percentage of space used by each folder.

Install dust

You can install dust using Rust's Cargo package manager:

$ cargo install du-dust

Alternately, you might find it in your software repository on Linux, and on macOS, use MacPorts or Homebrew.

Explore dust

Issuing the dust command on a directory returns a graph that shows its contents and what percentage each item holds in a tree format.

$ dust
 5.7M   ┌── exa                                                           │                                                ██ │   2%
 5.9M   ├── tokei                                                         │                                                ██ │   2%
 6.1M   ├── dust                                                          │                                                ██ │   2%
 6.2M   ├── tldr                                                          │                                                ██ │   2%
 9.4M   ├── fd                                                            │                                                ██ │   4%
 2.9M   │ ┌── exa                                                         │                                              ░░░█ │   1%
  15M   │ ├── rustdoc                                                     │                                              ░███ │   6%
  18M   ├─┴ bin                                                           │                                              ████ │   7%
  27M   ├── rg                                                            │                                            ██████ │  11%
 1.3M   │     ┌── libz-sys-1.1.3.crate                                    │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │   0%
 1.4M   │     ├── libgit2-sys-0.12.19+1.1.0.crate                         │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │   1%
 4.5M   │   ┌─┴ github.com-1ecc6299db9ec823                               │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │   2%
 4.5M   │ ┌─┴ cache                                                       │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │   2%
 1.0M   │ │   ┌── git2-0.13.18                                            │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   0%
 1.4M   │ │   ├── exa-0.10.1                                              │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   1%
 1.5M   │ │   │ ┌── src                                                   │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   1%
 2.2M   │ │   ├─┴ idna-0.2.3                                              │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   1%
 1.2M   │ │   │       ┌── linux                                           │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   0%
 1.6M   │ │   │     ┌─┴ linux_like                                        │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   1%
 2.6M   │ │   │   ┌─┴ unix                                                │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   1%
 3.1M   │ │   │ ┌─┴ src                                                   │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   1%
 3.1M   │ │   ├─┴ libc-0.2.94                                             │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   1%
 1.2M   │ │   │     ┌── test                                              │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   0%
 2.6M   │ │   │   ┌─┴ zlib-ng                                             │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   1%
 904K   │ │   │   │   ┌── vstudio                                         │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   0%
 2.0M   │ │   │   │ ┌─┴ contrib                                           │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   1%
 3.4M   │ │   │   ├─┴ zlib                                                │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   1%
 6.1M   │ │   │ ┌─┴ src                                                   │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓██ │   2%
 6.1M   │ │   ├─┴ libz-sys-1.1.3                                          │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓██ │   2%
 1.6M   │ │   │     ┌── pcre                                              │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   1%
 2.5M   │ │   │   ┌─┴ deps                                                │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   1%
 3.8M   │ │   │   ├── src                                                 │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓█ │   1%
 7.4M   │ │   │ ┌─┴ libgit2                                               │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓██ │   3%
 7.6M   │ │   ├─┴ libgit2-sys-0.12.19+1.1.0                               │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓██ │   3%
  26M   │ │ ┌─┴ github.com-1ecc6299db9ec823                               │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████ │  10%
  26M   │ ├─┴ src                                                         │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████ │  10%
 932K   │ │   ┌── .cache                                                  │               ░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█ │   0%
  11M   │ │   │     ┌── pack-c3e3a51a17096a3078196f3f014e02e5da6285aa.idx │               ░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███ │   4%
 135M   │ │   │     ├── pack-c3e3a51a17096a3078196f3f014e02e5da6285aa.pack│               ░░░░░░▓▓███████████████████████████ │  53%
 147M   │ │   │   ┌─┴ pack                                                │               ░░░░░░█████████████████████████████ │  57%
 147M   │ │   │ ┌─┴ objects                                               │               ░░░░░░█████████████████████████████ │  57%
 147M   │ │   ├─┴ .git                                                    │               ░░░░░░█████████████████████████████ │  57%
 147M   │ │ ┌─┴ github.com-1ecc6299db9ec823                               │               ░░░░░░█████████████████████████████ │  57%
 147M   │ ├─┴ index                                                       │               ░░░░░░█████████████████████████████ │  57%
 178M   ├─┴ registry                                                      │               ███████████████████████████████████ │  69%
 257M ┌─┴ .                                                               │██████████████████████████████████████████████████ │ 100%
$ 

To apply dust to a specific directory:

$ dust ~/Work/

The -r option shows the output in reverse order, with root at the bottom:

$ dust -r ~/Work/

Using dust -d 3 returns three levels of subdirectories and their disk utilization:

$ dust -d 3 ~/Work/wildfly/jaxrs/target/classes
$ dust -d 3 ~/Work/wildfly/jaxrs/target/classes
 4.0K     ┌── jaxrs.xml                                                           │                                         █ │   1%
 4.0K   ┌─┴ subsystem-templates                                                   │                                         █ │   1%
 4.0K   │   ┌── org.jboss.as.controller.transform.ExtensionTransformerRegistration│                                         █ │   1%
 4.0K   │   ├── org.jboss.as.controller.Extension                                 │                                         █ │   1%
 8.0K   │ ┌─┴ services                                                            │                                         █ │   2%
 8.0K   ├─┴ META-INF                                                              │                                         █ │   2%
 4.0K   │ ┌── jboss-as-jaxrs_1_0.xsd                                              │                                        ░█ │   1%
 8.0K   │ ├── jboss-as-jaxrs_2_0.xsd                                              │                                        ░█ │   2%
  12K   ├─┴ schema                                                                │                                        ██ │   3%
 408K   │   ┌── as                                                                │  ████████████████████████████████████████ │  94%
 408K   │ ┌─┴ jboss                                                               │  ████████████████████████████████████████ │  94%
 408K   ├─┴ org                                                                   │  ████████████████████████████████████████ │  94%
 432K ┌─┴ classes                                                                 │██████████████████████████████████████████ │ 100%
$ 

Conclusion

The beauty of dust lies in being a small, simple, and easy-to-understand command. It uses a color scheme to denote the largest subdirectories, making it easy to visualize your directory. It's a popular project, and contributions are welcome.

Have you used or considered using dust? If so, please let us know your thoughts in the comments below.

What to read next
Sudeshna is from Kolkata and currently working for the Red Hat Middleware team in Pune, India. She loves to explore different open source projects and programs. She started contributing to Open Source a couple of years back as an Hacktober Participant since then she has been an avid blogger at Dzone on Python and Data Science. She enjoys her free time stargazing and loves continental cuisine. She is an RHCSA and is working her way to RHCA.
Sudeshna is from Kolkata and currently working for the Red Hat Middleware team in Pune, India. She loves to explore different open source projects and programs. She started contributing to Open Source a couple of years back as an Hacktober Participant since then she has been an avid blogger at Dzone on Python and Data Science. She enjoys her free time stargazing and loves continental cuisine.

5 Comments

This looks visually confusing to me. du gives me everything I want to see when I use it.

The command du is fast and simple and works very well for my needs. I am seeing some edge cases where dust could be beneficial, but nothing with a compelling reasons to switch to it.

ncdu is much nicer and doesn't need extra dependencies.

Surely, the cargo command has more to offer than just dust. I also didn't care for the default install directory, $HOME/.cargo/bin. I installed dust this way:
$ sudo cargo install du-dust --root /usr/local/bin/cargo
WHeeee! So much output! Which I'll quote in a moment. Bottom line is the advice to add /usr/local/bin/cargo/bin to my PATH.

OK, about that output:
Updating crates.io index
Downloaded du-dust v0.6.0
Downloaded 1 crate (86.3 KB) in 0.75s
Installing du-dust v0.6.0
Downloaded ansi_term v0.11.0
Downloaded atty v0.2.14
Downloaded ansi_term v0.12.1
Downloaded autocfg v1.0.1
Downloaded bitflags v1.2.1
Downloaded cfg-if v1.0.0
Downloaded aho-corasick v0.7.18
Downloaded crossbeam-channel v0.5.1
Downloaded crossbeam-deque v0.8.0
Downloaded clap v2.33.3
Downloaded crossbeam-epoch v0.9.5
Downloaded crossbeam-utils v0.8.5
Downloaded either v1.6.1
Downloaded lazy_static v1.4.0
Downloaded libc v0.2.97
Downloaded lscolors v0.7.1
Downloaded memchr v2.4.0
Downloaded memoffset v0.6.4
Downloaded num_cpus v1.13.0
Downloaded rayon v1.5.1
Downloaded rayon-core v1.9.1
Downloaded regex v1.5.4
Downloaded scopeguard v1.1.0
Downloaded regex-syntax v0.6.25
Downloaded stfu8 v0.2.4
Downloaded term_size v0.3.2
Downloaded strsim v0.8.0
Downloaded terminal_size v0.1.17
Downloaded textwrap v0.11.0
Downloaded thousands v0.2.0
Downloaded unicode-width v0.1.8
Downloaded vec_map v0.8.2
Downloaded 32 crates (2.1 MB) in 1.08s
Compiling libc v0.2.97
Compiling autocfg v1.0.1
Compiling crossbeam-utils v0.8.5
Compiling lazy_static v1.4.0
Compiling cfg-if v1.0.0
Compiling memchr v2.4.0
Compiling crossbeam-epoch v0.9.5
Compiling scopeguard v1.1.0
Compiling rayon-core v1.9.1
Compiling bitflags v1.2.1
Compiling unicode-width v0.1.8
Compiling regex-syntax v0.6.25
Compiling strsim v0.8.0
Compiling ansi_term v0.11.0
Compiling ansi_term v0.12.1
Compiling either v1.6.1
Compiling vec_map v0.8.2
Compiling thousands v0.2.0
Compiling lscolors v0.7.1
Compiling memoffset v0.6.4
Compiling rayon v1.5.1
Compiling crossbeam-channel v0.5.1
Compiling aho-corasick v0.7.18
Compiling num_cpus v1.13.0
Compiling term_size v0.3.2
Compiling atty v0.2.14
Compiling terminal_size v0.1.17
Compiling textwrap v0.11.0
Compiling regex v1.5.4
Compiling clap v2.33.3
Compiling crossbeam-deque v0.8.0
Compiling stfu8 v0.2.4
Compiling du-dust v0.6.0
Finished release [optimized] target(s) in 1m 13s
Installing /usr/local/bin/cargo/bin/dust
Installed package `du-dust v0.6.0` (executable `dust`)

Back to me... What are all those other items? I tried the same command on some of the other packages listed up there. Example:
$ sudo cargo install clap --root /usr/local/bin/cargo

Now I don't know if it was necessary to continue specifying the --root option but trying to install this item, clap (whatever that is), yielded this error message:
$ sudo cargo install clap --root /usr/local/bin/cargo
Updating crates.io index
error: specified package `clap v2.33.3` has no binaries

After gettin this acouple of time you kinda get discouraged. How would I get a binaries that *are* really available for download? And do I need to always specify the --root option?

Whew! Too long but most of that is quoting my output.

This is new to me. Seems really good. Cheers.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.