CARGO-CLEAN(1)
β¨ CARGO-CLEAN(1) β¨
okay bestie, welcome to the General Commands Manual section 1, where we're talking about cargo-clean β the little command that yeets your build artifacts into the void π
π NAME π
cargo-clean β Remove generated artifacts π§Ήβ¨
π¦ SYNOPSIS π¦
cargo clean [options]
π DESCRIPTION π
So basically, this deletes the artifacts that Cargo made for you in the past, out of the target directory. Like, the stuff it generated. Gone. Bye π«Ά
And listen, with no options at all, cargo clean will delete the entire target directory. The whole thing. Not a drill, not a drill ππ
πΈ OPTIONS πΈ
π Package Selection π
Real talk: when no packages are selected, all packages and all dependencies in the workspace get cleaned. Everyone's coming to the party whether they like it or not β¨
-pspecβ¦,--packagespecβ¦ β clean only the packages you name. You can drop this flag as many times as you want (multiple times = multiple packages). Wanna know what the SPEC format even is? Run tocargo-pkgid(1), she explains it π
π§Ό Clean Options π§Ό
--dry-runβ shows you a lil summary of what would get deleted, without actually deleting anything. Very "window shopping" of it ποΈ Pro tip from the page: pair it with--verboseand it'll show you the actual files that would be deleted.--docβ this makescargo cleanremove only the doc directory inside the target directory. Just the docs, nothing else, she's selective π--releaseβ removes all artifacts sitting in the release directory π₯--profilename β removes all artifacts in the directory with the profile name you give it.--target-dirdirectory β the directory for all generated artifacts and intermediate files. You can also set this with theCARGO_TARGET_DIRenvironment variable, or with thebuild.target-dirconfig value <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, obvi. The general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>. Runrustc --print target-listfor a whole list of 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>.
Heads up 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/guide/build-cache.html> for more details.
π Display Options π
-v,--verboseβ verbose output. You can specify it twice for "very verbose" output, which throws in extra output like dependency warnings and build script output. Also settable with theterm.verboseconfig value <https://doc.rust-lang.org/cargo/reference/config.html>.-q,--quietβ do not print cargo log messages. Also settable with theterm.quietconfig value <https://doc.rust-lang.org/cargo/reference/config.html>.--colorwhen β controls when colored output is used. Valid values are:auto(default): automatically detect if color support is available on the terminal.always: always display colors.never: never display colors.
Also settable with the term.color config value <https://doc.rust-lang.org/cargo/reference/config.html>.
π Manifest Options π
--manifest-pathpath β path to theCargo.tomlfile. By default, Cargo searches forCargo.tomlin the current directory or any parent directory.--frozen,--lockedβ either one of these flags requires that theCargo.lockfile is up-to-date. If the lock file is missing, or it needs updating, Cargo will exit with an error. The--frozenflag also stops Cargo from trying to access the network to figure out if it's out-of-date. Use these in environments where you want to assert thatCargo.lockis up-to-date (like a CI build), or where you want to avoid network access entirely π--offlineβ prevents Cargo from accessing the network for any reason. Without this flag, Cargo will stop with an error if it needs the network and the network isn't there. With this flag, Cargo will try to proceed without the network if it possibly can.
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.
Also settable with the net.offline config value <https://doc.rust-lang.org/cargo/reference/config.html>.
π Common Options π
+toolchainβ if Cargo was installed with rustup, and the first argument tocargobegins with+, it gets interpreted as a rustup toolchain name (like+stableor+nightly). See the rustup documentation <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 given 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 info.-CPATH β changes the current working directory before executing any specified operations. This affects stuff like where cargo looks by default for the project manifest (Cargo.toml), and also the directories it searches for discovering.cargo/config.toml, for example. This option must appear before the command name, likecargo -C path/to/my-project build.
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-options flag to enable (see #10098 <https://github.com/rust-lang/cargo/issues/10098>).
-h,--helpβ prints help information.-Zflag β 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 environment variables that Cargo reads π
β EXIT STATUS β
0: Cargo succeeded π101: Cargo failed to complete π
π EXAMPLES π
- Remove the entire target directory:
cargo clean
- Remove only the release artifacts:
cargo clean --release
π¦ SEE ALSO π¦
and that's the whole page, bestie π it's from the General Commands Manual, page CARGO-CLEAN(1), and the footer's just sitting down there echoing CARGO-CLEAN(1) one more time like the icon it is. no cap. periodt πβ¨π«Ά
π¦ where this page comes from
- ubuntu jammy: cargo-1.77 1.77.2+dfsg1ubuntu1~bpo0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.77 1.77.2+dfsg1ubuntu1-0ubuntu0.24.04.1 Β· 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