Clean up Rust target folders

targetnext toCargo.toml

Quick answer

Yes, Rust's target folder is safe to delete. It holds compiled artifacts and incremental caches; the next cargo build recreates it, just more slowly the first time.

Rebuild with cargo build

What is it?

target/ is Cargo's build directory: debug and release builds of your crate and every dependency, incremental-compilation caches, test binaries and docs.

Why does it get so big?

  • Separate debug and release builds
  • Incremental compilation caches
  • Old dependency versions left after cargo update
  • Full debug info by default in dev builds
  • A new set per toolchain and per cross-compile target

How to clean it from the command line

cargo clean

Review what a command matches before you run anything with rm -rf. These deletions are permanent.

What not to delete

  • Cargo.toml and Cargo.lock
  • ~/.cargo/registry and ~/.cargo/git (shared download caches)
  • Installed binaries in ~/.cargo/bin

How Gigaflush handles Rust

Gigaflush lists target only when Cargo.toml sits right beside it, shows each folder's size, preselects nothing, and re-checks the folder immediately before deleting it. Symlinks and parent-directory paths are refused.

FAQ

Is it safe to delete the target folder in Rust?

Yes. It's entirely generated by Cargo. Your next build recompiles everything.

Why is my Rust target folder so large?

Cargo keeps debug and release builds, incremental caches, full debug info and old dependency builds, and never garbage-collects them automatically.

How do I stop target from growing?

Share a CARGO_TARGET_DIR for small projects, reduce debug info in [profile.dev], and run cargo clean or cargo sweep after big updates.

Further reading