Skip to content

M4cs/targkill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🦀 targkill

Easily find and reclaim the gigabytes that Rust target/ directories eat up.

Like npkill, but for Cargo. A blazing-fast, parallel filesystem scanner wrapped in a friendly terminal UI — list every target/ directory on your machine, see how much space each one is wasting, and wipe the ones you don't need.

CI crates.io Downloads License: MIT


targkill scanning a tree of Cargo projects, then selecting and deleting target/ directories

💡 The bar at the top animates while scanning, then fills in as each directory's size is computed. Sizes appear live — you don't wait for the whole scan to finish.

✨ Features

  • Fast — parallel, multi-threaded directory walk powered by jwalk; target dirs are pruned mid-walk so their huge contents are never traversed.
  • 🎯 Accurate — only real Cargo targets (a target/ with a sibling Cargo.toml) are listed. A random folder named target is never touched.
  • 📊 Live sizing — every directory is measured the moment it's found, concurrently with the rest of the scan, with a running "reclaimable" total.
  • 🖥️ Interactive TUI — built on ratatui; navigate, multi-select, sort, and delete without leaving the terminal.
  • 🧵 Tunable — pick the worker-thread count with -j/--threads.
  • 💽 Whole-system or scoped — scan every drive at once, or point it at a specific folder.
  • 🛡️ Safe by default — deletions ask for a y/N confirmation and run in the background so the UI never freezes.
  • 📜 Scriptable--list prints results as plain text for piping into other tools.
  • 🪟 Cross-platform — Linux, macOS, and Windows.

📦 Install

From crates.io (recommended)

cargo install targkill

Prebuilt binaries

Grab a binary for your platform from the latest release, unpack it, and put cargo-targkill somewhere on your PATH.

From source

cargo install --git https://github.com/M4cs/targkill
# or, from a local clone:
git clone https://github.com/M4cs/targkill && cd targkill
cargo install --path .

All of these install a cargo-targkill binary, which Cargo exposes as a subcommand. You can run it either way:

cargo targkill      # via Cargo
cargo-targkill      # directly (it's on your PATH)

🚀 Usage

cargo targkill                  # no path: every drive (Windows) / your home dir (macOS, Linux)
cargo targkill ~/dev            # scan a specific folder, recursively
cargo targkill ~/dev /work      # scan multiple roots
cargo targkill -j 8 ~/dev       # use 8 worker threads (default: one per core)
cargo targkill --list ~/dev     # print results and exit (no TUI)

Options

Option Description
[PATH...] Roots to scan recursively. Defaults to every drive on Windows, or your home directory on macOS/Linux.
-j, --threads <N> Worker threads for scanning & sizing. 0/omitted = auto (one per core).
-l, --list Print discovered dirs and sizes to stdout, then exit. Great for scripts.
-h, --help Show help.

Keybindings

Key Action
/ , j / k Move the cursor
g / G Jump to top / bottom
space Toggle selection of the current row
a / n Select all / select none
s Cycle sort order — size → name → age
d / Del Delete the selection (or current row), after a y/N confirm
q / Esc Quit

Directories ≥ 1 GiB are highlighted so the big wins jump out.

🔍 How it works

  1. Discover. A parallel jwalk traversal visits the tree. Whenever a directory contains a Cargo.toml, its target/ child is recorded as a candidate and the walker is told not to descend into it — so the (potentially massive) build artifacts are never walked. .git directories are skipped entirely for speed.
  2. Size. The instant a candidate is found, a sizing task is dispatched onto a separate thread pool. Sizes stream back into the UI as they complete, independent of the ongoing discovery walk.
  3. Delete. Selected directories are removed with std::fs::remove_dir_all on a background thread, so even multi-gigabyte deletes keep the interface responsive.

Discovery and sizing run on independent multi-threaded pools, so a slow size computation never stalls discovery, and vice-versa.

⚠️ targkill performs a permanent delete — there is no recycle bin / trash. Deleting a target/ is harmless (Cargo regenerates it on the next build), but double-check the path before confirming.

🛠️ Building

git clone https://github.com/M4cs/targkill
cd targkill
cargo build --release   # binary at target/release/cargo-targkill

Requires a recent stable Rust toolchain (rustup recommended).

🤝 Contributing

Issues and pull requests are welcome! CI runs rustfmt, clippy -D warnings, and the test suite across Linux, macOS, and Windows — please run cargo fmt and cargo clippy --all-targets -- -D warnings before opening a PR.

📄 License

MIT © Max Bridgland (@M4cs)

About

List any cargo target folders in your environment and clean them up

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages