Rust's target directory can grow to 5-10GB per project. If you're working on multiple Rust projects, you might have 50GB or more consumed by target directories alone.
This guide explains what's inside target/, why it gets so large, and how to safely clean it.
What's Inside the Rust target Directory?
The target directory contains all Cargo-generated build artifacts:
target/
├── debug/ # Debug build artifacts
│ ├── deps/ # Compiled dependencies (largest)
│ ├── build/ # Build script outputs
│ ├── incremental/ # Incremental compilation cache
│ └── my-binary # Your compiled binary
├── release/ # Release build artifacts
├── doc/ # Generated documentation (cargo doc)
├── package/ # Packaged crates (cargo package)
└── .fingerprint/ # Build tracking metadata
Where Does the Size Come From?
The deps/ folder is the main culprit:
| Content | Why It's Large |
|---|---|
| Compiled dependencies | 200+ transitive deps compiled to native code |
| Debug symbols | Debug builds include full symbol tables |
| Multiple versions | Different deps may require different versions |
| Incremental cache | Speeds rebuilds but consumes space |
A typical web framework project's debug build exceeds 2GB just in deps.
Why Does Rust target Get So Large?
Multiple Build Profiles
Each profile has its own complete dependency tree:
target/
├── debug/ # cargo build
├── release/ # cargo build --release
├── custom/ # Custom profiles in Cargo.toml
Cross-Compilation Targets
Building for multiple platforms multiplies size:
target/
├── x86_64-unknown-linux-gnu/
├── aarch64-apple-darwin/
├── wasm32-unknown-unknown/
├── x86_64-pc-windows-msvc/
Each target has its own complete build.
Cargo Workspaces
Workspaces share a single target directory—efficient for builds, but creates one massive folder.
Incremental Compilation
Rust caches partial compilation state for faster rebuilds. This cache grows over time.
Typical Rust target Directory Sizes
| Project Type | Debug Build | Release Build | Total |
|---|---|---|---|
| CLI tool | 1-2GB | 500MB-1GB | 2-3GB |
| Web server (Actix/Axum) | 2-4GB | 1-2GB | 3-6GB |
| GUI app (Tauri/egui) | 3-5GB | 1-3GB | 4-8GB |
| With multiple targets | 5-10GB | 2-5GB | 7-15GB |
Across 10 Rust projects, you could easily have 50GB in target directories.
How to Clean Rust target Directory
Using cargo clean (Single Project)
# Remove entire target directory
cargo clean
# Remove only release artifacts
cargo clean --release
# Remove specific package only
cargo clean --package my-crate
Find All Rust target Directories
# List all target directories
find ~/projects -name "target" -type d -prune 2>/dev/null
# Show sizes sorted by largest
find ~/projects -name "target" -type d -prune -exec du -sh {} \; 2>/dev/null | sort -hr
# Total size
find ~/projects -name "target" -type d -prune -exec du -sh {} \; 2>/dev/null | awk '{sum+=$1} END {print sum "GB total"}'
Delete All Rust target Directories
find ~/projects -name "target" -type d -prune -exec rm -rf {} + 2>/dev/null
Warning: This deletes ALL target directories, including active projects.
Find all your Rust target directories
Cluttered scans your entire system and shows sizes at a glance.
Is It Safe to Delete Rust target/?
Yes, always. The target directory contains only generated files. Cargo recreates everything from source on your next build.
What Happens After Deletion
| Action | After cargo clean |
|---|---|
| First compile | Full rebuild: 30 seconds to several minutes |
| Subsequent compiles | Incremental builds resume |
| Binary location | Regenerated in target/debug or target/release |
If you're not actively working on a project, there's no reason to keep its target folder.
Using Cluttered for Rust Cleanup
Cluttered provides intelligent Rust cleanup:
- Finds all Rust projects across your entire system
- Shows target directory sizes at a glance
- Identifies active vs dormant projects
- Protects uncommitted work via git status checks
- Trash-first deletion for easy recovery
Why Cluttered Is Better Than Manual Cleanup
| Feature | cargo clean / find | Cluttered |
|---|---|---|
| Cleans single project | ✅ | ✅ |
| Finds all projects | Manual | ✅ Automatic |
| Shows project activity | ❌ | ✅ |
| Checks git status | ❌ | ✅ |
| Trash-first deletion | ❌ | ✅ |
| Cleans Cargo cache too | ❌ | ✅ |
Reducing Rust target Size
1. Use sccache for Shared Compilation
cargo install sccache
export RUSTC_WRAPPER=sccache
Shares compiled artifacts between projects, reducing per-project size.
2. Reduce Debug Symbol Size
In .cargo/config.toml:
[profile.dev]
debug = 1 # Reduced from default 2
split-debuginfo = "unpacked" # macOS: smaller on-disk size
3. Clean Before Archiving
Before backing up or committing to version control:
cargo clean
Never store gigabytes of regenerable data.
4. Use Lighter Dependencies
Some crates compile faster and smaller:
# Instead of full tokio
tokio = { version = "1", features = ["rt", "macros"] }
# Instead of all serde features
serde = { version = "1", features = ["derive"] }
Rust target vs Cargo Cache
Don't confuse them:
| Location | Contents | Command to Clean |
|---|---|---|
project/target/ | Build artifacts | cargo clean |
~/.cargo/registry/ | Downloaded crates | cargo cache --autoclean |
~/.cargo/git/ | Git dependencies | cargo cache --autoclean |
For complete Rust cleanup, clean both. See our Cargo cache cleanup guide.
How Much Disk Space Can You Recover?
| Developer Profile | Rust Projects | Avg target Size | Recoverable |
|---|---|---|---|
| Hobbyist | 5-10 | 2GB | 10-20GB |
| Professional | 10-20 | 3GB | 30-60GB |
| Heavy Rust user | 20+ | 4GB | 80-100GB+ |
Most Rust developers recover 20-50GB from target cleanup alone.
Stop Running Out of Disk Space
Cluttered finds and cleans node_modules, Rust targets, Xcode DerivedData, Docker cache, and more. Reclaim 50-100GB in minutes.
Frequently Asked Questions
Does deleting target affect Cargo.toml or Cargo.lock?
No. Those files are in your project root, not target/. They're never affected.
Will I need to re-download dependencies?
No. Dependencies are cached globally in ~/.cargo/registry/. Only recompilation happens.
Can I delete target while cargo is running?
No. Wait for builds to complete first. Deleting during compilation causes errors.
How do I clean a specific build target?
cargo clean --target x86_64-unknown-linux-gnu
Should I add target to .gitignore?
Yes, always. It's already in Rust's default .gitignore:
/target/
How often should I clean target directories?
Monthly for dormant projects. Active projects benefit from keeping the cache.
Conclusion
Rust's target directory is essential for fast incremental compilation, but dormant projects don't need 5GB build caches sitting idle.
Regular cleanup—whether with cargo clean, manual deletion, or Cluttered—should be part of your Rust development workflow.
Download Cluttered to automate Rust cleanup alongside 11 other development ecosystems.