CARGO-CLEAN(1)
π NAME π
cargo-clean β the moment you finally clear out all the generated artifacts, no cap β¨
This one lives in the General Commands Manual, section 1, so you already know it's a certified banger of a page.
β¨ SYNOPSIS β¨
cargo clean [options]
π¦ DESCRIPTION π¦
Okay so bestie, picture this: your target directory has been collecting artifacts that Cargo generated in the past like it's a hoarder with main character energy. cargo clean is here to Remove generated artifacts. The girl cleans. π§Ήβ¨
And if you pass no options at all? She's not being subtle. cargo clean will delete the entire target directory. Whole thing. Gone. Periodt. π
π OPTIONS π
Package Selection
Heads up, queen: when no packages are selected, all packages and all dependencies in the workspace are cleaned. Everybody gets the treatment. π
-pspecβ¦,--packagespecβ¦ β Clean only the specified packages. You can drop this flag multiple times if you're feeling extra. The SPEC format lives over incargo-pkgid(1), iykyk.
Clean Options
--dry-runβ Shows you a lil summary of what would get deleted, without deleting a single thing. It's giving window shopping ποΈ. Pair it with--verboseif you want to see the actual files that would be deleted β the receipts, basically.--docβ Makescargo cleanremove only thedocdirectory inside the target directory. Just the docs, nothing else, she's being selective.--releaseβ Removes all artifacts in thereleasedirectory. Bye girl π--profilename β Removes all artifacts in the directory with that given profile name.--target-dirdirectory β Where all the generated artifacts and intermediate files go. You can also set this with theCARGO_TARGET_DIRenvironment variable, or thebuild.target-dirconfig value at https://doc.rust-lang.org/cargo/reference/config.html. Defaults totargetin the root of the workspace. π--targettriple β Clean for the given architecture. Default is the host architecture. The general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>. Runrustc --print target-listfor a list of supported targets. This flag may be specified multiple times. π
This may also be specified with the build.target config value at https://doc.rust-lang.org/cargo/reference/config.html.
Heads up though: specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. Check the build cache docs at https://doc.rust-lang.org/cargo/guide/build-cache.html for more details. π
Display Options
-v,--verboseβ Use verbose output. Specify it twice for "very verbose" output, which includes extra stuff like dependency warnings and build script output. May also be set with theterm.verboseconfig value at https://doc.rust-lang.org/cargo/reference/config.html. She's chatty and we love that π¬-q,--quietβ Do not print cargo log messages. May also be set with theterm.quietconfig value at https://doc.rust-lang.org/cargo/reference/config.html. Silence is golden β¨--colorwhen β Controls when colored output is used. Valid values, bestie:auto(default): Automatically detect if color support is available on the terminal. π€always: Always display colors. πnever: Never display colors. π«
May also be set with the term.color config value at https://doc.rust-lang.org/cargo/reference/config.html.
Manifest Options
--manifest-pathpath β Path to theCargo.tomlfile. By default, Cargo searches for theCargo.tomlfile in 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 may be used in environments where deterministic builds are desired, such as in CI pipelines. Fr fr, your CI will thank you.
--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 is not 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. π«Ά
May also be set with the net.offline config value at https://doc.rust-lang.org/cargo/reference/config.html.
--frozenβ Equivalent to specifying both--lockedand--offline. Two-for-one deal, iconic. π
Common Options
+toolchain β If Cargo has been installed with rustup, and the first argument tocargobegins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). See the rustup documentation at https://rust-lang.github.io/rustup/overrides.html for more info on how toolchain overrides work. π--configKEY=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 at https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides for more information.-CPATH β 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. π
This option is only available on the nightly channel at https://doc.rust-lang.org/book/appendix-07-nightly-rust.html and requires the -Z unstable-options flag to enable (see #10098 at https://github.com/rust-lang/cargo/issues/10098). Nightly girlies only, sorry π
-h,--helpβ Prints help information. The classic. π-Zflag β Unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details. π
π ENVIRONMENT π
See the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for the details on environment variables that Cargo reads. All the tea is there π΅
β EXIT STATUS β
0: Cargo succeeded. π₯³ Slay.101: Cargo failed to complete. π It's giving not today.
πΈ EXAMPLES πΈ
- Remove the entire
targetdirectory:
cargo clean
- Remove only the release artifacts:
cargo clean --release
π SEE ALSO π
And that's the whole page, bestie β straight from the General Commands Manual, this is cargo-clean(1), section 1. Go forth and clean your target directory, you absolute icon. π«Άβ¨π
π¦ where this page comes from
- ubuntu jammy: cargo-1.80 1.80.1+dfsg0ubuntu1~bpo0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.80 1.80.1+dfsg0ubuntu1-0ubuntu0.24.04.01 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms