LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

cargo-clean

Remove build artifacts from a Rust project

TLDR

Remove entire target directory
$ cargo clean
copy
Remove release artifacts only
$ cargo clean --release
copy
Remove documentation only
$ cargo clean --doc
copy
Clean specific package
$ cargo clean -p [package]
copy
Preview without deleting
$ cargo clean --dry-run
copy
Clean specific profile
$ cargo clean --profile [dev]
copy
Clean for specific target architecture
$ cargo clean --target [x86_64-unknown-linux-gnu]
copy
Preview with verbose file listing
$ cargo clean --dry-run -v
copy

SYNOPSIS

cargo clean [options]

DESCRIPTION

cargo clean removes build artifacts generated by Cargo from the target directory. With no options, deletes the entire target directory. When packages are selected with -p, only those package artifacts are removed.

PARAMETERS

--release

Remove artifacts in the release directory.
--profile name
Remove artifacts for the specified build profile.
--doc
Remove only the doc directory in the target directory.
-p, --package spec
Clean only the specified packages. May be specified multiple times.
--target triple
Clean for the specified target architecture. May be specified multiple times.
--target-dir dir
Custom target directory path.
--dry-run
Show what would be deleted without actually deleting.
-v, --verbose
Use verbose output. May be specified twice for very verbose output.
-q, --quiet
Do not print cargo log messages.
--color WHEN
Control when colored output is used (auto, always, never).
--manifest-path path
Path to Cargo.toml.

CAVEATS

Without package selection, cleans all packages and dependencies in the workspace. The target directory can grow very large; regular cleaning frees significant disk space but requires a full rebuild afterward.

SEE ALSO

Copied to clipboard
Kai