MIT License

项目介绍

Byron/dua-cli 是一个托管在 GitHub 上的开源项目,主要使用 Rust 编写,采用 MIT License 许可证,目前获得 6.4k 个 Star、180 次 Fork。

仓库全名
Byron/dua-cli
开源许可证
MIT License
Star 数
6.4k
Fork 数
180

README 摘要

dua (-> Disk Usage Analyzer) is a tool to conveniently learn about the usage of disk space of a given directory. It's parallel by default and will max out your SSD, providing relevant information as fast as possible. Optionally delete superfluous data, and do so more quickly than rm. Run dua i to launch the interactive mode for exploring and deleting files. Installation Binary Release MacOS MacOS via MacPorts: MacOS…

完整内容见 GitHub 原始 README 或本页 。

常见问题

dua-cli 用什么语言开发?

主要使用 Rust 编写,采用 MIT License 许可证,目前有 6.4k 个 Star。

dua-cli 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 dua-cli 的源码?

可以直接克隆仓库:git clone https://github.com/Byron/dua-cli.git,默认分支为 main;安装与运行步骤见仓库 README。

dua-cli 最近还在维护吗?

仓库最近一次更新为 4 天前,当前没有未关闭的 Issue;Star 数为 6.4k,可作为社区活跃度的参考。

简要分析

热度分
6805
价值分
3907
活跃状态
活跃

语言占比

Dockerfile
Just
Makefile
Rust
Shell

Release

README

Rust Crates.io Packaging status

dua (-> Disk Usage Analyzer) is a tool to conveniently learn about the usage of disk space of a given directory. It’s parallel by default and will max out your SSD, providing relevant information as fast as possible. Optionally delete superfluous data, and do so more quickly than rm.

Run dua i to launch the interactive mode for exploring and deleting files.

asciicast

Installation

Binary Release

MacOS
curl -LSfs https://raw.githubusercontent.com/Byron/dua-cli/master/ci/install.sh | \
    sh -s -- --git Byron/dua-cli --crate dua
MacOS via MacPorts:
sudo port selfupdate
sudo port install dua-cli
MacOS via Homebrew
brew update
brew install dua-cli
Linux

Linux requires the target to be specified explicitly to obtain the MUSL build.

curl -LSfs https://raw.githubusercontent.com/Byron/dua-cli/master/ci/install.sh | \
    sh -s -- --git Byron/dua-cli --target x86_64-unknown-linux-musl --crate dua
Windows via Scoop
scoop install dua
Windows via WinGet
winget install Byron.dua-cli
Pre-built Binaries

See the releases section for manual installation of a binary, pre-built for many platforms.

Release archives include build provenance attestations. After downloading an archive, verify that it was built by this repository with the GitHub CLI:

gh attestation verify ./dua-v2.39.1-aarch64-apple-darwin.tar.gz --repo Byron/dua-cli
Cargo

Via cargo, which can be obtained using rustup

For Unix…

cargo install dua-cli

# And if you don't need a terminal user interface (most compatible)
cargo install dua-cli --no-default-features

# Compiles on most platforms, with terminal user interface
cargo install dua-cli --no-default-features --features tui-crossplatform

For Windows, nightly features are currently required.

cargo +nightly install dua-cli
VoidLinux

Via xbps on your VoidLinux system.

xbps-install dua-cli
Fedora

Via dnf on your Fedora system.

sudo dnf install dua-cli
Arch Linux

Via pacman on your ArchLinux system.

sudo pacman -S dua-cli
NixOS

https://search.nixos.org/packages?query=dua

Nix-shell (temporary)

nix-shell -p dua

NixOS configuration

  environment.systemPackages = [
    pkgs.dua
  ];
NetBSD

Via pkgin on your NetBSD system.

pkgin install dua-cli

Or, building from source

cd /usr/pkgsrc/sysutils/dua-cli
make install
Windows

You will find pre-built binaries for Windows in the releases section. Alternatively, install via cargo as in

cargo +nightly install dua-cli
x-cmd

x-cmd is a toolbox for Posix Shell, offering a lightweight package manager built using shell and awk.

x env use dua
  • Additionally, the x dua ... command is available, which automatically installs dua without affecting the environment, such as not modifying the PATH variable.

Usage

# count the space used in the current working directory
dua
# count the space used in all directories that are not hidden
dua *
# learn about additional functionality
dua aggregate --help

On macOS, the --deduplicate-apfs-clones traversal option counts fully shared APFS file clones only once in aggregate and interactive runs. It is opt-in because collecting the additional metadata reduces traversal performance. Files that share only some blocks are not deduplicated, and --apparent-size still reports each file’s logical length.

Tree output

By default aggregate prints a flat listing. Pass --depth N to instead print an indented tree that descends N levels into each input, which is handy for sharing a disk-usage report without opening interactive mode. The inputs form the first level, so --depth 1 lists just them, the same set of entries the flat listing shows.

# show each top-level entry and one level below it
dua aggregate --depth 2

--no-sort and --no-total work the same way they do for the flat listing.

Excluding paths with a pattern file

--ignore-from FILE reads gitignore-style patterns and leaves everything they match out of the report, in both aggregate and interactive mode. This is the --exclude-from of rsync and the --exclude-file of restic, so the same file can answer “how much of this would actually get backed up?”.

cat .duaignore
# /target/
# **/node_modules/
# *.log
# !important.log

dua --ignore-from .duaignore

Patterns follow .gitignore syntax - # comments, a trailing / to match directories only, a leading / to anchor to the current working directory or the traversal root, ** to span directories, and ! to re-include something an earlier pattern excluded. They match the paths dua reports, which are relative to the directory being looked at, and matching is case-sensitive on every platform.

The option can be given more than once, in which case later files win over earlier ones, and it can also be set through DUA_IGNORE_FROM. Excluded directories are not descended into at all, so their contents cannot be re-included - the same restriction Git has.

Interactive Mode

Launch into interactive mode with the i or interactive subcommand. Get help on keyboard shortcuts with ?. Use this mode to explore, and/or to delete files and directories to release disk space.

Press ] to minimize or restore the entire right side. Tab cycles through visible panes; ? restores and focuses Help when the right side is minimized.

Please note that great care has been taken to prevent accidental deletions due to a multi-stage process, which makes this mode viable for exploration.

dua i
dua interactive

The interactive interface can be localized via the standard POSIX locale environment variables, in the usual order of precedence LC_ALL > LC_MESSAGES > LANG. English is the default. The following translations are listed in the order they were added: German (de), Japanese (ja), Korean (ko), and Simplified Chinese (zh, zh_CN, zh_SG, or zh_Hans). They are available when the locale uses UTF-8 or omits the codeset:

Please open an issue to request support for your language, if you would be available for reviewing it as well.

LANG=de_DE.UTF-8 dua i   # German interface
LANG=ja_JP.UTF-8 dua i   # Japanese interface
LANG=ko_KR.UTF-8 dua i   # Korean interface
LANG=zh_CN.UTF-8 dua i   # Simplified Chinese interface

Cleanup Mode

dua clean [DIRECTORY]... finds disposable directories and lists them largest first as sizing finishes. With no paths, it searches the current directory. Nothing is deleted automatically.

dua clean ~/dev
dua clean --depth 3 ~/dev ~/Downloads

Candidates include node_modules, Python caches and virtual environments, Cargo project target directories, and Zig’s .zig-cache, zig-cache, and zig-out. In Git repositories, candidates must be ignored and contain no tracked files. Directories containing a .git entry (regardless of case) and paths excluded by traversal options are skipped.

The hub groups sibling candidates and deeper candidates under their shared parent. Open a group to browse, sort, or search within it; go back to return to the hub. Use the usual marking and deletion keys. Marking a group selects only its candidates, leaving other contents untouched.

  • R in the hub repeats discovery; r rechecks the selected candidate or existing group members.
  • Inside a candidate, either refresh key rechecks the whole candidate. Refresh clears all marks.
  • Discovery is unlimited by default. --depth 0 checks only the supplied directories for great speedups; candidates are always sized completely.

Traversal options, --no-entry-check, and --once are supported. Parent scanning, snapshot import, and snapshot export are unavailable.

Flame graphs

dua stacks prints folded stacks—the “collapsed” interchange format read by flame-graph tools. Each line is an entry’s path with ; between its components, a space, and its size in bytes:

dua stacks > disk-usage.folded

dua flamegraph renders the same data with inferno, writes the SVG to a temporary file, and opens it. Pass an output path to write the SVG without opening it. Both commands accept the usual traversal options as well as --depth and --import:

dua flamegraph
dua flamegraph -o disk-usage.svg

Configuration

dua can read an optional configuration file from your OS-specific config directory:

  1. Linux/Unix: $XDG_CONFIG_HOME/dua-cli/config.toml (or the platform default config dir)
  2. macOS: ~/Library/Application Support/dua-cli/config.toml
  3. Windows: %APPDATA%\dua-cli\config.toml

If the file is missing, defaults are used.

Run dua config show-default for a commented template containing every configurable keybinding. Use a string for one binding or an array for aliases; an empty array disables the action. For example:

[keys]
# If true (default), close_pane keys ascend from the main pane.
# If false, close_pane keys follow the quit behavior.
esc_navigates_back = true

close_pane = "esc"
toggle_right_panes = "]"
sort_by_name = "ctrl+n"

# Disable permanent deletion and moving entries to the trash.
delete_marked = []
trash_marked = []

Development

Please note that all the following assumes a unix system. On Windows, the linux subsystem should do the job.

Run tests
make tests
Check release compatibility

Starting with dua-cli 3.0.0, the dua Rust library is experimental and its API may change in minor releases. Library consumers should use a tilde requirement, such as ~3.0.0, to receive compatible patch updates. The dua command-line interface follows semantic versioning, and dua-core retains its stable Rust API.

Both workspace crates configure Rust API checks in their Cargo.toml metadata. Use a cargo-smart-release build that includes cargo api-check, Rust 1.99 (rustdoc JSON format 61), and cargo-semver-checks 0.51.0 or newer.

Preview the release, including stable workspace dependencies, with just:

just smart-release

Run just without arguments to list available recipes. Additional arguments to just smart-release are forwarded to cargo smart-release.

This is a dry run. The recipe’s rustdoc allowance is needed for public links to private items in older release tags; it does not disable API checks. It can be removed once both release baselines contain the corrected documentation.

Learn about other targets
make
But why is…
…there only one available backend? termion was available previously.

Maintaining both backends seemed more cumbersome than it’s worth and add complexity I didn’t like anymore. termion had its benefits, but I never liked that it seems to have dropped out of support. Thus crossterm is the only remaining backend and it’s very actively developed.

Limitations

  • Does not show symbolic links at all if no path is provided when invoking dua
    • in an effort to skip symbolic links, for now there are pruned and are not used as a root. Symbolic links will be shown if they are not a traversal root, but will not be followed.
  • Interactive mode only looks good in dark terminals (see this issue)
  • easy fix: file names in main window are not truncated if too large. They are cut off on the right.
  • There are plenty of examples in tests/fixtures which don’t render correctly in interactive mode. This can be due to graphemes not interpreted correctly. With Chinese characters for instance, column sizes are not correctly computed, leading to certain columns not being shown. In other cases, the terminal gets things wrong - I use alacritty, and with certain characters it performs worse than, say iTerm3. See https://github.com/minimaxir/big-list-of-naughty-strings/blob/master/blns.txt for the source.
  • In interactive mode, you will need about 60MB of memory for 1 million entries in the graph.
  • In interactive mode, the maximum amount of files is limited to 2^32 - 1 (u32::max_value() - 1) entries.
    • One node is used as to ‘virtual’ root
    • The actual amount of nodes stored might be lower, as there might be more edges than nodes, which are also limited by a u32 (I guess)
    • The limitation is imposed by the underlying petgraph crate, which declares it as unsafe to use u64 for instance.
    • It’s possibly UB when that limit is reached, however, it was never observed either.

Similar Programs

评论

暂无评论