关于 dust
dust 是一个磁盘使用量分析工具,以可视化树形结构展示目录占用空间。支持按深度过滤和交互式浏览,帮助快速定位大文件和目录。
主要功能
- 01以直观的树形图展示每个目录和文件的磁盘占用
- 02限制显示深度快速识别最大的磁盘消耗目录
- 03在终端中交互式浏览和探索目录树
- 04与脚本和自动化工作流集成
适用场景
- 01开发者分析项目目录和 node_modules 等大型文件夹的存储占用
- 02系统管理员识别服务器上占用空间最多的目录进行清理
- 03编码 Agent 自动检测和报告存储瓶颈
安装
选择你的系统或包管理器,复制命令到终端运行。
安装完成后运行dust --version确认安装成功。
命令示例
常用命令按使用顺序排列。
详细介绍
Dust
du + rust = dust。就像 du,但更直观。
为什么
因为我想轻松查看磁盘空间的使用情况。
演示
观看上面的演示
-
我们进入一个大小为 72K 的 webapp 目录。
-
我们看到
src文件夹占用 32K。注意,进度条跳到 44%。webapp 的一半内容都在 src 中。 -
我们看到
src/utils占用 8K。进度条降到 11%,但仍有一道阴影停留在 44%,表示它属于src文件夹。 -
接着演示
-d 2标志——显示深度为 2 的文件夹。 -
接着演示
-n 5标志——仅显示 5 个项目(默认显示与终端高度相同数量的项目)。
安装
快速安装(Linux、macOS、Windows)
curl -sSfL https://raw.githubusercontent.com/bootandy/dust/refs/heads/master/install.sh | sh
Cargo 
Cargo
cargo install du-dust
🍺 Homebrew(Mac OS)
brew install dust
🍺 Homebrew(Linux)
brew install dust
DNF(Fedora Linux)
sudo dnf install du-dust
Snap Ubuntu 和受支持的系统
snap install dust
注意:通过 snap 安装的 dust 只能访问存储在 /home 目录中的文件。更多信息请参阅 danie-dejager/dust-snap#2。
mise
mise use -g dust
Pacstall(Debian/Ubuntu)
pacstall -I dust-bin
Anaconda(conda-forge)
conda install -c conda-forge dust
deb-get(Debian/Ubuntu)
deb-get install du-dust
x-cmd
x env use dust
Windows:
scoop install dust- Windows GNU 版本——可用
- Windows MSVC——需要:VCRUNTIME140.dll
下载
- 从 Releases 下载 Linux/Mac 二进制文件
- 解压文件:
tar -xvf _downloaded_file.tar.gz - 将文件移至可执行文件路径:
sudo mv dust /usr/local/bin/
概述
Dust 旨在让你即时了解哪些目录正在占用磁盘空间,无需使用 sort 或 head。Dust 最多只会打印一条“没有权限”消息。
Dust 会列出略少于终端高度数量的最大子目录或文件,并智能地向下遍历目录树以查找较大的项目。无需使用 -d 或 -h 标志。最大的子目录会以颜色标示。
进度条上的不同颜色代表目录树层级和磁盘使用情况。灰色深浅用于表示子文件夹所属的父文件夹。例如,请看上方的截图。.steam 是一个占用 44% 空间的文件夹。从 .steam 的进度条上方延伸出一条浅灰色线。所有这些文件夹都在 .steam 中,因此删除 .steam 后,这些内容也会一并删除。
如果你刚开始使用这个工具,我建议尝试调整 -n 参数,例如 dust -n 10、dust -n 50。
用法
Usage: dust
Usage: dust <dir>
Usage: dust <dir> <another_dir> <and_more>
Usage: dust -p (full-path - Show fullpath of the subdirectories)
Usage: dust -s (apparent-size - shows the length of the file as opposed to the amount of disk space it uses)
Usage: dust -n 30 (Shows 30 directories instead of the default [default is terminal height])
Usage: dust -d 3 (Shows 3 levels of subdirectories)
Usage: dust -D (Show only directories (eg dust -D))
Usage: dust -F (Show only files - finds your largest files)
Usage: dust -r (reverse order of output)
Usage: dust -o si/b/kb/kib/mb/mib/gb/gib (si - prints sizes in powers of 1000. Others print size in that format).
Usage: dust -X ignore (ignore all files and directories with the name 'ignore')
Usage: dust -x (Only show directories on the same filesystem)
Usage: dust -b (Do not show percentages or draw ASCII bars)
Usage: dust -B (--bars-on-right - Percent bars moved to right side of screen)
Usage: dust -i (Do not show hidden files)
Usage: dust -c (No colors [monochrome])
Usage: dust -C (Force colors)
Usage: dust --dim (Dim the percent bars to reduce brightness on dark terminals)
Usage: dust -f (Count files instead of diskspace [Counts by inode, to include duplicate inodes use dust -f -s])
Usage: dust -t (Group by filetype)
Usage: dust -z 10M (min-size, Only include files larger than 10M)
Usage: dust -e regex (Only include files matching this regex (eg dust -e "\.png$" would match png files))
Usage: dust -v regex (Exclude files matching this regex (eg dust -v "\.png$" would ignore png files))
Usage: dust -L (dereference-links - Treat sym links as directories and go into them)
Usage: dust -P (Disable the progress indicator)
Usage: dust -T (Set the number of walker threads. Default is the CPU count. For high-latency storage like NFS or remote mounts, a higher count can speed up the walk by overlapping more concurrent stat calls.)
Usage: dust -R (For screen readers. Removes bars/symbols. Adds new column: depth level. (May want to use -p for full path too))
Usage: dust --skip-total (No total row will be displayed)
Usage: dust -z 40000/30MB/20kib (Exclude output files/directories below size 40000 bytes / 30MB / 20KiB)
Usage: dust -j (Prints JSON representation of directories, try: dust -j | jq)
Usage: dust --files0-from=FILE (Read NUL-terminated file paths from FILE; if FILE is '-', read from stdin)
Usage: dust --files-from=FILE (Read newline-terminated file paths from FILE; if FILE is '-', read from stdin)
Usage: dust --collapse=node-modules will keep the node-modules folder collapsed in display instead of recursively opening it
Usage: dust --dim Displays dimmer bars
配置文件
Dust 有一个配置文件,可用于设置上述选项。
配置文件可以是 $XDG_CONFIG_HOME/dust/config.toml(如果没有,则使用
~/.config/dust/config.toml),也可以是 ~/.dust.toml。
$ cat ~/.config/dust/config.toml
reverse=true
limit-filesystem=true
键名使用长标志名称并采用 kebab-case。更完整的示例请参阅 config/config.toml。
替代方案
- NCDU
- dutree
- dua
- pdu
- dirstat-rs
du -d 1 -h | sort -h
为什么选择 Dust,而不是替代方案
处理大量小文件和目录时,Dust 会以简单直接的方式完成该做的事。Dust 只显示较大的条目,让输出保持简洁。
ncdu 和 baobab 等工具可以显示目录大小,但你无法知道最大的文件在哪里。例如,目录 A 的大小可能大于目录 B,但最大的文件实际上在 B 中,而不在 A 中。通过其他工具找出这一点并不容易,而 Dust 会在树形层级中清晰地显示大文件。
Dust 不会重复计算硬链接(除非你想使用 -s)。
输入 dust -n 90 将显示最大的 90 个条目。-n 与 head -n 或 tail -n 不完全相同;Dust 很智能,会挑选最大的条目。