CARGO-CLEAN(1)
okay so bestie π your target directory is giving hoarder house and it's time for a cleanse. this is the cargo-clean page from the General Commands Manual (section 1), and it's literally the glow-up ritual your project has been begging for. β¨
πΈ NAME πΈ
cargo-clean β remove generated artifacts π§Ήβ¨
π¦ SYNOPSIS π¦
cargo clean [options]
π DESCRIPTION π
Removes artifacts from the target directory that Cargo generated in the past. it's giving spring cleaning, it's giving "we don't talk about that old build anymore." π
β οΈ heads up bestie: with no options at all, cargo clean will delete the entire target directory. not some of it. all of it. gone. periodt. π
β¨ OPTIONS β¨
π Package Selection π
When no packages are selected, all packages and all dependencies in the workspace get cleaned. so like, everything, girl.
-p specβ¦,--package specβ¦β only clean the packages you name. you can drop this flag multiple times if you wanna list several. peepcargo-pkgid(1)for the SPEC format. π
π§Ή Clean Options π§Ή
--dry-runβ shows you a lil summary of what would get deleted without deleting a single thing. the way thatβ¦ you can pair it with--verboseto see the actual files that would be yeeted. π--docβ makescargo cleanremove only thedocdirectory inside the target directory. just the docs, nothing else.--releaseβ nukes all artifacts in thereleasedirectory. π₯--profile nameβ nukes all artifacts in the directory with the profile name you hand it.--target-dir directoryβ where all generated artifacts and intermediate files live. you can also set this with theCARGO_TARGET_DIRenvironment variable, or thebuild.target-dirconfig value (https://doc.rust-lang.org/cargo/reference/config.html). defaults totargetin the root of the workspace.--target tripleβ clean for the architecture you name. the default is the host architecture. general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>. runrustc --print target-listto see the supported targets. this flag may be specified multiple times.
you can also set this with the build.target config value (https://doc.rust-lang.org/cargo/reference/config.html).
ngl bestie, specifying this flag makes Cargo run in a different mode where the target artifacts get placed in a separate directory. see the build cache docs (https://doc.rust-lang.org/cargo/reference/build-cache.html) for more details.
π Display Options π
-v,--verboseβ verbose output. specify it twice for "very verbose" output, which includes extra output like dependency warnings and build script output. you can also set this with theterm.verboseconfig value (https://doc.rust-lang.org/cargo/reference/config.html).-q,--quietβ do not print cargo log messages. silent mode, main character energy. you can also set this with theterm.quietconfig value (https://doc.rust-lang.org/cargo/reference/config.html).--color whenβ controls when colored output gets used. valid values:auto(default): automatically detect if color support is available on the terminal.always: always display colors. πnever: never display colors.
you can also set this with the term.color config value (https://doc.rust-lang.org/cargo/reference/config.html).
π Manifest Options π
--manifest-path pathβ path to theCargo.tomlfile. by default Cargo searches forCargo.tomlin the current directory or any parent directory.--lockedβ asserts that the exact same dependencies and versions are used as when the existingCargo.lockfile was originally generated. Cargo will exit with an error when either of these scenarios arises:- the lock file is missing.
- Cargo attempted to change the lock file due to a different dependency resolution.
it can be used in environments where deterministic builds are desired, like CI pipelines. π
--offlineβ prevents Cargo from accessing the network for any reason. without this flag, Cargo will stop with an error if it needs to access the network and the network isn't available. with this flag, Cargo will attempt to proceed without the network if possible.
beware bestie: this may result in different dependency resolution than online mode. Cargo will restrict itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. see the cargo-fetch(1) command to download dependencies before going offline.
you can also set this with the net.offline config value (https://doc.rust-lang.org/cargo/reference/config.html).
--frozenβ equivalent to specifying both--lockedand--offline. two-for-one deal. π--lockfile-path PATHβ changes the path of the lockfile from the default (<workspace_root>/Cargo.lock) to PATH. PATH must end withCargo.lock(e.g.--lockfile-path /tmp/temporary-lockfile/Cargo.lock). note that providing--lockfile-pathwill ignore the existing lockfile at the default path, and instead will either use the lockfile from PATH, or write a new lockfile into the provided PATH if it doesn't exist. this flag can be used to run most commands in read-only directories, writing the lockfile into the provided PATH.
this option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the-Z unstable-optionsflag to enable (see #14421https://github.com/rust-lang/cargo/issues/14421). β¨
β Common Options β
+toolchainβ if Cargo was installed with rustup, and the first argument tocargobegins with+, it gets interpreted as a rustup toolchain name (such as+stableor+nightly). see the rustup documentation (https://rust-lang.github.io/rustup/overrides.html) for more information about how toolchain overrides work.--config KEY=VALUE or PATHβ overrides a Cargo configuration value. the argument should be in TOML syntax ofKEY=VALUE, or provided as a path to an extra configuration file. this flag may be specified multiple times. see the command-line overrides section (https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides) for more information.-C PATHβ changes the current working directory before executing any specified operations. this affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering.cargo/config.toml, for example. this option must appear before the command name, for examplecargo -C path/to/my-project build.
only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the-Z unstable-optionsflag to enable (see #10098https://github.com/rust-lang/cargo/issues/10098). β¨
-h,--helpβ prints help information. π«Ά-Z flagβ unstable (nightly-only) flags to Cargo. runcargo -Z helpfor details.
πΏ ENVIRONMENT πΏ
see the reference (https://doc.rust-lang.org/cargo/reference/environment-variables.html) for details on the environment variables that Cargo reads. iykyk.
π EXIT STATUS π
0: Cargo succeeded. slay. π101: Cargo failed to complete. π
πΈ EXAMPLES πΈ
- Remove the entire target directory:
cargo clean
- Remove only the release artifacts:
cargo clean --release
π¦ SEE ALSO π¦
okay that's the whole page bestie π it's CARGO-CLEAN(1) out of the General Commands Manual, and the footer line was literally just CARGO-CLEAN(1) again β like, the manual said its own name twice, iconic. πβ¨ go forth and clean, and remember: the facts stayed exactly the same, only the vibe got upgraded. π
π¦ where this page comes from
- ubuntu jammy: cargo-1.85 1.85.1+dfsg0ubuntu2~bpo0-0ubuntu1.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.85 1.85.1+dfsg0ubuntu2~bpo0-0ubuntu0.24.04.2 Β· Apache-2.0 WITH LLVM exception
- ubuntu questing: cargo-1.85 1.85.1+dfsg0ubuntu2-0ubuntu1
- ubuntu questing: cargo-1.85 1.85.1+dfsg0ubuntu2-0ubuntu1.25.04.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms