Rust is filling your disk
Two culprits: per-project
target/ folders and the
global ~/.cargo cache. A busy workspace's target
folder easily reaches 10-20 GB (debug + release + every dependency's
artifacts), and cargo's registry keeps every crate version you ever
compiled. Both fully regenerate.
Find the target folders
find ~ -name target -type d -prune -path "*/src/../target" 2>/dev/null | head
# simpler, with sizes (will include some non-Rust 'target' dirs – check paths):
find ~ -name target -type d -prune -exec du -sh {} + 2>/dev/null | sort -rh | head -20
cargo clean # inside a project – removes its target/
The global cargo cache
du -sh ~/.cargo/registry ~/.cargo/git
rm -rf ~/.cargo/registry/cache # downloaded .crate files
rm -rf ~/.cargo/registry/src # extracted sources
Everything re-downloads from crates.io on the next build that needs it.
Rustup toolchains
rustup toolchain list
rustup toolchain uninstall nightly-2024-03-15 # old pinned nightlies add up, ~1 GB each
Automate the sweep
cargo install cargo-sweep then cargo sweep --time 30
removes artifacts older than 30 days from a target folder – good for the
projects you're actively working on.
For everything else, CacheCleaner finds every target/
across the disk (only real Rust projects – it checks for
Cargo.toml), plus the cargo registry, git checkouts and
old rustup toolchains, with sizes for each.