disktree README

项目的 README,来自 github.com/tobi/disktree。合并为一个 markdown 文件:README.md。

disktree

disktree: a home directory as a treemap, coloured by kind of data, with reclaimable space hatched and the selection, findings and free space in the side panel

Find what is filling a disk, mark what should go, and remove it — with the volume's free space in view the whole time.

disktree is a treemap for Omarchy. It starts by scanning your home directory; the location picker switches to another folder, volume or SSH source. It draws every directory as a nested mosaic sized by its disk usage, and lets you walk into it with the keyboard or the mouse. Mark as much as you like; nothing happens until you review the list and commit, and the permanent path always asks first.

Built with GPUI through gpui-omarchy, so it follows your Omarchy theme and font, and behaves like the rest of the desktop.

Install

Download disktree-*-x86_64-linux.tar.gz (aarch64-linux on ARM) from the latest release, unpack it, and run ./install.sh inside (or just copy disktree onto your PATH). Or build it:

git clone https://github.com/tobi/disktree
cd disktree
make install

make install builds a release binary and puts three things under ~/.local (no root needed):

sudo make install PREFIX=/usr/local installs system-wide; make uninstall removes exactly what was installed.

On Arch, including Omarchy, disktree is in the AUR: disktree builds each release from source, and disktree-bin installs the release binary:

yay -S disktree-bin

If another installed version wins on PATH, the installer warns which one. Run export PATH="$HOME/.local/bin:$PATH" and add that setting to your shell configuration so the locally installed build takes precedence.

For Linux builds with embedded SSH helpers, also install the two Rust standard-library targets (no external C cross-compiler is needed):

rustup target add x86_64-unknown-linux-musl aarch64-unknown-linux-musl

You need Rust 1.97 or newer and a Wayland or X11 session with a GPU that GPUI can drive (Vulkan). Distributions often package an older Rust; rustup installs a current one. The repo pins 1.97 in rust-toolchain.toml, so with rustup the right toolchain is fetched on the first build even if rustup default points at something older.

macOS

Download disktree-*-aarch64-macos.zip (x86_64-macos for an Intel Mac) from the latest release, unzip it, and drag disktree.app into Applications. macOS 11 or newer.

A release that was not signed and notarized is stopped by Gatekeeper: macOS says it "is damaged and can't be opened" or "cannot be verified". The app is fine; the browser marked the download as quarantined. Clear the mark once:

xattr -dr com.apple.quarantine /Applications/disktree.app

(Or open it once, then choose Open Anyway in System Settings › Privacy & Security.)

Or build it, with Rust 1.97 or newer and Xcode or its Command Line Tools. macOS does not come with Rust; install it with rustup.

make install     # ~/Applications/disktree.app, and ~/.local/bin/disktree
make uninstall

To see everything, give disktree Full Disk Access in System Settings › Privacy & Security (the panel offers a button when it is missing), then reopen it. Without it macOS hides Mail, Messages, Safari, other apps' data and the Trash, and disktree counts them as unreadable. Started from a terminal, it is the terminal that needs the access. macOS also asks once each for Desktop, Documents and Downloads.

What is different from Linux:

To sign and notarize a build for others, with a Developer ID certificate in the keychain and credentials saved by xcrun notarytool store-credentials:

NOTARY_PROFILE=<profile> cargo xtask bundle \
  --sign "Developer ID Application: Name (TEAMID)" --notarize

Windows

On Windows 10 or 11, download disktree-*-x86_64-windows-setup.exe (aarch64-windows on ARM, Windows 11) from the same release and run it. It installs for you alone, with no administrator prompt, unless you choose all users on its first page; it adds disktree to the Start menu and the desktop, and to Settings > Apps to uninstall. A newer setup upgrades in place.

The setup is not signed, so SmartScreen says "Windows protected your PC"; choose More info, then Run anyway.

To skip installing, download disktree-*-x86_64-windows.zip instead, unpack it anywhere and run disktree.exe. Or build it with Rust 1.97 or newer, from rustup, and the MSVC toolchain (Visual Studio Build Tools, C++ workload):

git clone https://github.com/tobi/disktree
cd disktree
cargo build --release    # target\release\disktree.exe

See On Windows for what differs there.

Use

disktree            # choose a local/SSH source and root
disktree ~          # explicitly scan home
disktree --disk     # the whole disk it lives on
disktree ~/src      # or any directory
disktree --help     # options: apparent size, follow links, skip hidden, …

Servers over SSH (read-only)

disktree ssh dev                 # connect and choose a remote root
disktree ssh user@server /var    # an explicit remote path
disktree ssh dev --disk          # the disk containing the remote home
disktree ssh dev -a /srv         # apparent size instead of allocated blocks

Linux builds made with make build / cargo xtask portable include static x86-64 and ARM64 Linux scanners appended to the executable. SSH detects the server's OS/CPU and uploads the matching scanner only when its checked cache is missing or damaged. The cache is private and content-addressed under ~/.cache/disktree/ssh/<sha256>/ (or the server's XDG_CACHE_HOME). Uploads are checksum-verified and atomically installed; there is no sudo, system-package change or dependency on the server's glibc version.

This uses stable Rust's musl targets rather than Cosmopolitan: the existing Rust/rayon/rustix scanner has no supported stable Cosmopolitan target. These are Linux binaries, not a single executable for every OS; ARM64 is built and ELF-validated, while x86-64 was also executed against a real server.

You can extract a helper without opening a window, or test the entire SSH/deployment/scan path headlessly:

disktree extract-scanner x86_64 ./disktree-scan
disktree extract-scanner aarch64 ./disktree-scan-arm64
disktree ssh dev --check /var/log

The appended manifest stores architecture, byte ranges and SHA-256 hashes. Do not run strip after packaging: it discards the trailer. The Linux release pipeline strips first, embeds last, and ships that single file. Appending to signed macOS/Windows executables needs platform-specific signature handling; those builds do not yet embed helpers.

For a development or non-Linux desktop build without the trailer, install the small disktree-scan helper on the server first:

# On the server, inside the checkout:
make install-scan               # ~/.local/bin/disktree-scan; no GUI deps
# Or:
cargo install --path crates/disktree-scan --locked

The helper can be on the server's non-interactive SSH PATH or at ~/.local/bin/disktree-scan (the default install location); disktree tries both. A binary copied from another machine must match the server's OS, architecture and runtime. The manually built native helper may need the server's libc; the embedded Linux helpers are static. Disktree never runs sudo or changes the server's configuration. SSH keeps your normal authentication settings. When launched from a terminal, it can ask for a password or key passphrase there; GUI launches need key/agent access or a working SSH askpass helper. Connect once with ssh dev to verify access and accept its host key.

The protocol also supports lightweight root discovery, separate from a scan: it reads the target's mount namespace without walking or probing the listed paths. Same-device mounts remain distinct choices; capacity is unknown until a root is explicitly selected. Discovery requests omit scan fields, so outdated helpers reject them instead of silently scanning their home.

The Linux/macOS helper streams a depth-first walk directly to stdout. It never constructs a tree or retains a directory's children: memory scales with open ancestors, not file count. Deep directories are not rejected at an arbitrary depth; filesystem errors are reported as unreadable. Hardlink identities are sent to the desktop, which uses the local scanner's compact identity index to count each inode once. The helper keeps no per-file identity table in negotiated desktop-de-duplication mode; links outside the chosen root cannot fill one. Older clients retain bounded helper-side accounting for wire compatibility. A resource limit fails explicitly instead of returning a partial tree. Symlinks are not followed, and every nested mount is skipped, even a bind mount or same-device subvolume. Select those as separate roots.

While indexing, a quiet sidebar shows live files, directories, measured bytes, read errors and elapsed time. Counters and paths use monospace type in fixed lanes; changing values do not re-center or reflow the screen. Narrow windows use a compact progress footer instead.

Ordinary local walks and current SSH helpers paint a live top-level overview before the full tree arrives. These are measured contributions, not complete directory sizes. Updates are limited to once a second, in arrival order, with at most 128 named buckets plus an overflow bucket. The preview is kept separate from the real tree: it cannot be navigated, marked or removed. On completion the full, actionable treemap replaces it; on error or cancellation the preview is discarded. The Windows file-table fast path still waits for its complete tree. Remote scans also show a sampled recent directory and connection / helper setup / indexing / treemap stages. Progress uses a single replaceable snapshot, not a growing event queue; path updates are throttled to five per second. There is no guessed percentage: the total is unknown until the walk finishes. Older helpers still provide counters from their streamed records, without path samples.

One compressed SSH connection carries a bounded JSON request on stdin and compact postorder records on stdout. The client keeps stdin open so the helper exits on disconnect, including while scanning or blocked on output. Linux helpers also enforce a 1 GiB address-space ceiling, disable core dumps, and stop after five minutes. File contents never cross the connection and paths are never interpolated into remote shell commands. Only the desktop retains the complete tree for offline navigation; its memory still scales with entry count. The native Windows helper currently retains the original tree-building scan path.

Remote mode is export-only. Mark with Space, open review with c, then:

There are no trash/delete buttons or removal-mode choices in remote review. Deletion shortcuts and removal entry points are disabled too. Git inspection, local folder selection and file-manager reveal are disabled so remote names cannot accidentally act on this computer. Free space is sampled when the scan starts, not live; press r to refresh.

Before deleting, scripts compare the server's actual kernel hostname and machine ID against the identity captured in the scan—not the SSH alias. Missing identity or any mismatch aborts. The check runs on the SSH target, not the computer launching the wrapper. Pasting the script previews it by default and runs in a subshell, so its exit cannot close your terminal.

Exports are not an automatic cleanup recommendation. Scripts refuse system paths, the scan root, home or its ancestors, symlinked/changed canonical paths, and paths containing mount points. Control-character names are omitted. These checks do not eliminate filesystem races or tell you whether git work is backed up; review the script and prefer a tool's own cleanup command for tool-owned data. The remote helper itself has no delete operation.

The screen

One colour is kept apart: amber marks the selection, the main action, and what can be had back.

The kinds come from directory names and a few shapes (a bare git repository, target beside a Cargo.toml). Some of the names are specific to one machine; see crates/disktree-core/src/classify.rs.

Marking

Space, X, Enter and the arrows act on the tile under the mouse if the mouse moved last, and on the keyboard selection after you use an arrow or Tab.

A marked tile takes the danger colour, and so does everything inside it: removing a directory takes its contents with it. Marking a directory absorbs any marks already inside it, and something inside a marked directory cannot be marked or kept on its own; its panel offers to unmark the directory instead. Marking is reversible — press it again — and the saving is never counted twice.

Zooming and going in

Scroll to magnify toward the pointer. The wheel magnifies until the directory under the pointer fills the view, and the next notch goes into it — one continuous motion, with the directory's contents growing into place. Scroll the other way to come back out. Enter goes into the selected directory at any depth, and Backspace or Escape goes up one level. < and >, beside the Size / Files / Age switch, go back and forward through the directories visited, as do alt ← alt → (also ⌘[ ⌘] on macOS) and the mouse's side buttons. + and - magnify without going in; 0 resets.

Removing

c (or Review…) opens the list of everything marked. Unmark anything there, then choose:

When it finishes, disktree scans again so the numbers on screen match the disk, and shows how much free space was actually gained.

Keys

key does
space / x mark or unmark the tile you point at
ctrl-click (⌘-click on macOS) mark without moving the selection
enter open that directory, at any depth
⌫ / esc go up one directory
alt ← alt → back and forward through where you have been
← ↑ ↓ → move between tiles at this level
tab next largest sibling
scroll zoom toward a directory, then go into it
shift-scroll pan the magnified view
[ ] draw fewer or more levels at once
- = 0 magnify, shrink, reset the view
ctrl = ctrl - ctrl 0 (⌘ on macOS) interface zoom
/ filter by name: only matches keep their colour; enter shows only them, esc clears
c review the marked list
t size, files or age: what areas and colours say
d disk usage or apparent size
i include or skip hidden entries
r refresh the scanned root in the background
esc while scanning stop the scan
v choose a local/SSH source and root
ctrl o (⌘O on macOS) choose another directory to scan
g the whole disk
p show or hide the selection line
o show it in Finder, File Explorer or the file manager
right-click show that tile in Finder, File Explorer or the file manager
? every key
q quit

On macOS the menu bar also has ⌘⇧R to show the selection in Finder, ⌘R to rescan, ⌘[ and ⌘] for back and forward, and ⌘Q, ⌘H and ⌘W (closing the window quits); other ⌘ chords are left to the system. On Linux and Windows the same work with ctrl, with F5 to rescan too.

The key list closes with esc, its Close button, or a click outside it.

On the review screen: m trash, p permanent, ! unmark all, enter commits, esc goes back. Or hand the list on instead of acting on it: s saves it as a text file, one path per line, and a copies a prompt for a coding agent: free the space by removing what you picked, checking each path first (git work that exists nowhere else, a tool's own clean command) and touching nothing else. A name holding a newline is left out of the list and escaped in the prompt, so it cannot pass for another path.

What it measures

The scan follows dust's approach: one rayon scope per root, a completion counter per directory so no directory is built before its last subdirectory lands, and one bottom-up pass that aggregates sizes and removes duplicate hardlinks.

Choosing sources and roots

Launch without a path to choose This computer or enter an SSH alias / user@host and press Connect SSH. Discovery reads that machine's mount namespace, not file contents. It never starts a scan or probes mounted network filesystems just to fill the list.

Select a mount and choose Scan selected root, or enter an absolute directory path and choose Scan directory. Enter acts on the focused host/path field or the highlighted mount. Escape cancels discovery and returns to the current scan, or the idle welcome screen at startup.

During exploration, press v, click Source… beside the disk name, or click the disktree logo to reopen the same chooser. The source being browsed is shown explicitly, and connecting never retargets an existing scan. Changing machines on acceptance clears the old machine's marks, identity and navigation history; an absolute path is not an identity across hosts. A rescan that detects a changed or lost remote machine identity also clears marks, even if the SSH alias is unchanged.

Pseudo-filesystems, snapshots and automount triggers are filtered out. Linux bind mounts and btrfs subvolumes remain individually selectable, even when they share a device. Free space is measured only after choosing a root. Explicit command-line paths and --disk still start directly; ssh HOST --check [PATH] remains the headless scan command.

The whole disk

Click / (or any directory above the scanned root) in the trail, press g, run disktree --disk, or use the launcher's Scan the whole disk action. g and --disk scan the disk your home directory lives on — / on Omarchy and on macOS. On macOS the Data volume's second mount, /System/Volumes/Data, is skipped: it is /Users, /Applications and the rest again under other names.

Widening is memoized: the tree already measured is handed to the wider walk and reused where it is reached, so going from ~ to / reads only what is outside ~ (on this machine, seconds instead of a full rescan). The current view stays on screen until the wider tree lands, which then opens with the directory you came from selected. Going back down is just navigation.

Local Linux scans include distinct Btrfs subvolumes on the same filesystem, so a / scan includes Omarchy's /home. Overlapping mount views, known snapshot mounts, other disks and network filesystems remain excluded. Mount boundaries are checked by path before reading a directory, so an automounted NAS is not activated just to measure its parent. Remote scans still stop at every nested mount; select another mount as its own root.

Local -X explicitly crosses mounts; remote streaming scans reject it. A local mark on another volume is still removed, but is not added to the metered volume's free-space projection.

Without root, some system directories cannot be read; they are counted as unreadable in the top bar rather than guessed at.

On Windows

The same program, with Windows' answers to the questions above:

What it refuses to do

The removal rules live in crates/disktree-core/src/removal.rs, and each one is tested:

On Hyprland

Hyprland tiles new windows, so disktree opens into whatever tile it is given. It is designed for a roomy window; float it, or give it a rule. The window class is disktree.

windowrule = float, class:^(disktree)$
windowrule = size 1400 900, class:^(disktree)$

Develop

make run      # release build, scanning your home directory
make lint     # rustfmt --check, then clippy with every warning an error
make test     # scanner, layout and removal tests, plus window-harness tests
make test-ssh # real localhost SSH scans/errors; Linux, bun + openssh required
make ci       # lint, then test

The lint gate is strict on purpose: clippy::all and clippy::pedantic are errors, and every exception is written down with its reason in Cargo.toml. The window-harness tests draw real frames and press real keys — including one that marks a directory, confirms the deletion and checks that the files are gone while their neighbours are not.

path what lives there
crates/disktree-core scanning, the tree, the squarified layout, free space and removal — no UI
crates/disktree-app/src/state.rs every action the interface can take, and the key map
crates/disktree-app/src/views.rs the screens
crates/disktree-app/src/treemap_view.rs painting the mosaic and its labels
crates/disktree-app/src/ui.rs the spacing, type and size scale, in rem
crates/disktree-app/src/tests.rs end-to-end tests through a real window
packaging/, assets/, Makefile the desktop entry, the icon, and install

The interface follows the GPUI Kit design guides: every size is on one rem scale so interface zoom keeps its proportions, primary is reserved for what Enter does, and the only question the app asks is the one it cannot take back.

License

MIT

disktree (tobi/disktree)

正在搜索数据库…

这是什么?disktree 是一款矩形树图可视化工具,用来找出是什么占满了你的磁盘:它把每个目录画成按实际占用空间大小嵌套的马赛克图,让你可以标记要删除的文件或文件夹,并始终显示整个卷的剩余空间。
它是命令行工具,还是图形界面应用?它是一个图形界面桌面应用,不是命令行工具——用 Rust 基于 GPUI 并通过 gpui-omarchy 构建,因此会遵循 Omarchy 主题,表现得像该桌面环境的原生组件。每个操作仍然配有键盘快捷键,不想用鼠标也行。
删除操作会立即永久生效吗?不会——标记文件或文件夹只是选中它;在你打开复核列表并选择“移到废纸篓”(可恢复)或“永久删除”之前不会有任何操作,而且永久删除选项总是先弹出确认对话框。
必须运行 Omarchy 吗,还是任何 Linux、Mac 或 Windows 机器上都能用?虽然以 Omarchy 为定位,它也提供面向通用 Linux、macOS 和 Windows 的预编译二进制,并针对各操作系统的回收站、磁盘统计和保护性系统文件夹做了专门处理。
为什么它看不到我 Mac 上的某些文件夹?在 macOS 上,disktree 需要在系统设置中授予完全磁盘访问权限(Full Disk Access),才能看到邮件、信息、Safari、其他应用的数据和废纸篓;没有该权限时这些会被计为不可读,而且如果你从终端启动它,需要授权的是终端本身。
Disk usage 和 Apparent size 有什么区别?Disk usage(磁盘占用)是默认项,反映 du 报告的数值,也是删除后实际能腾出的空间(stblocks × 512);Apparent size(表观大小)按一下键即可切换,是 `ls -l` 显示的原始文件大小,对稀疏文件或压缩文件来说两者可能相差很大。
我可以扫描整个磁盘而不只是主目录吗?可以——按 g、运行 `disktree --disk`,或使用启动器中的“Scan the whole disk”操作;扫描结果会被缓存,因此把范围从 ~ 扩大到 / 只会读取主目录以外的内容,而不会重新扫描全部。
如果我不想自己删,而是想要一份待删清单怎么办?在复核界面按 s 可把已标记的路径保存为纯文本文件,按 a 会复制一段现成的提示词给编程智能体,指示它通过删除这些路径来释放空间,除此之外什么都不要动。
为什么 macOS 显示的剩余空间可能比 Finder 少?disktree 报告的是 `df` 的数值,而 Finder 的数字还计入可清除空间(macOS 可自行清理的缓存和本地快照),因此 Finder 显示的剩余空间通常更大。
作者
tobi
大小
2 MB
星标
4.2K
时长
2个月
提交 · 90 天