dust du Replacement

dust cheatsheet — visualize disk usage with tree output. dust -d 3, dust -r, dust -n 20. More intuitive than du with bar graphs showing relative sizes.

4 min read

What it is

dust is a more visually appealing and interactive alternative to du for understanding disk usage in a directory.

Installation

Linux (using package managers):

# Debian/Ubuntu
sudo apt update && sudo apt install dust

# Fedora
sudo dnf install dust

# Arch Linux
sudo pacman -S dust

Linux (using cargo):

cargo install du-dust

Mac (using Homebrew):

brew install dust

Windows (using scoop):

scoop install dust

Core Concepts

dust works by recursively traversing directories and calculating the size of files and subdirectories. It presents this information in a hierarchical, color-coded tree format, making it easy to spot large directories.

Commands / Usage

Basic Usage

View disk usage in the current directory:

dust

This command shows a tree of directories and their sizes, sorted by size.

View disk usage in a specific directory:

dust /var/log

This command shows a tree of directories and their sizes within /var/log.

Filtering and Sorting

Limit the depth of the output:

dust -d 2

This command limits the output to directories up to 2 levels deep from the current directory.

Show only files larger than a certain size:

dust -s 100M

This command shows only entries (files or directories) that are at least 100 megabytes. You can use K for kilobytes, M for megabytes, G for gigabytes.

Sort by creation time (oldest first):

dust -s -t asc

This command sorts the output by creation time, with the oldest entries appearing first.

Sort by modification time (newest first):

dust -s -m desc

This command sorts the output by modification time, with the newest entries appearing first.

Sort by name:

dust -s -n

This command sorts the output alphabetically by name.

Display Options

Use SI units (powers of 1000) instead of binary units (powers of 1024):

dust -H

This command displays sizes using SI units (e.g., 1KB = 1000 bytes, 1MB = 1000 KB).

Display sizes in bytes:

dust -b

This command shows all sizes in bytes.

Use a percentage of the total size:

dust -p

This command displays each entry’s size as a percentage of the total disk usage in the current directory.

Show hidden files and directories:

dust -a

This command includes hidden files and directories (those starting with a dot .) in the scan.

Do not print the total size at the end:

dust --no-total

This command suppresses the display of the overall disk usage summary.

Interactive Mode

Enter interactive mode to navigate the directory tree:

dust -i

In interactive mode, you can use arrow keys to navigate, Enter to descend into a directory, and q to quit.

Ignoring Files and Directories

Ignore specific files or directories:

dust --ignore node_modules

This command will exclude any directory or file named node_modules from the scan. You can specify multiple ignore patterns.

Ignore files matching a glob pattern:

dust --ignore '*.log'

This command will ignore all files ending with .log.

Common Patterns

Find the largest directories in your home directory:

dust -d 3 ~

This command shows the top 3 levels of directories in your home directory, sorted by size, helping you quickly identify space hogs.

Clean up Docker images (requires Docker to be installed and running):

# First, see which images are taking up space
docker images | dust -a --ignore <none>

# Then, remove specific images (example)
docker rmi <image_id>

While dust doesn’t directly remove Docker images, it helps you identify which ones are consuming the most space.

Find large log files in /var/log:

dust -d 2 /var/log | grep -E '[0-9.]+[G]B|[0-9.]+[M]B'

This command lists directories and files in /var/log up to two levels deep and filters for entries larger than a few megabytes or gigabytes.

Find and remove large, old log files (use with extreme caution):

# First, identify large, old log files
dust -d 3 /var/log -s 500M -t asc | grep '\.log$'

# Then, if you are absolutely sure, remove them
# find /var/log -name "*.log" -size +500M -mtime +30 -delete

This pattern uses dust to identify potential candidates, and then a find command (which is more powerful for deletion) can be used. Always double-check before deleting.

Gotchas

  • Permissions: dust needs read permissions for directories to scan them. If you encounter permission denied errors, you might need to run it with sudo (though be cautious when running sudo with interactive tools).
  • Symlinks: By default, dust follows symbolic links. If you have many symlinks pointing to the same large directory, it might appear multiple times in the output. Use --no-symlink to prevent following symlinks.
  • Hidden files: By default, hidden files and directories (those starting with .) are not shown. Use the -a flag to include them.
  • Size calculation: The size reported is the disk space occupied by the files and directories, not necessarily the sum of the sizes of their contents due to file system block allocation and sparse files.