LinuxCommandLibrary

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
$ cargo clean --target [x86_64-unknown-linux-gnu]
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.

PARAMETERS

--release

Remove artifacts in release directory
--profile name
Remove artifacts for specified profile
--doc
Remove only documentation directory
-p, --package spec
Clean only specified packages
--target triple
Clean for specified target architecture
--target-dir dir
Custom target directory path
--dry-run
Show what would be deleted without deleting
-v, --verbose
Display actual files to be deleted (with --dry-run)

ENVIRONMENT

CARGO_TARGET_DIR

Override target directory location

CAVEATS

Without package selection, cleans all packages and dependencies in workspace. The target directory can grow very large; regular cleaning frees significant disk space.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community