CARGO-CLEAN(1)
π§Ό NAME π§Ό
okay so this is cargo-clean β the manual page for the cargo clean command, straight out of the General Commands Manual. Bestie, it removes generated artifacts. That's the whole vibe. β¨
π SYNOPSIS π
cargo clean [options]
short, sweet, iconic. π
π DESCRIPTION π
So basically, cargo clean goes into your target directory and removes the artifacts that Cargo generated in the past. Like, all that build residue? Gone. Poof. π«§
And if you run it with no options at all, cargo clean will delete the entire target directory. Not a little bit. The whole thing. No cap. π
βοΈ OPTIONS βοΈ
π¦ Package Selection π¦
When no packages are selected, all packages and all dependencies in the workspace are cleaned. Like, the whole friend group gets a glow-up. π
-p*spec*β¦,--package*spec*β¦ β clean only the specified packages. This flag may be specified multiple times (yes, stack 'em π). Seecargo-pkgid(1)for the SPEC format.
π§½ Clean Options π§½
--dry-runβ shows you a summary of what would be deleted, without actually deleting anything. It's giving window shopping ποΈ. Use it with--verboseto display the actual files that would be deleted.--docβ this option makescargo cleanremove only thedocdirectory in the target directory. Just the docs, nothing else. π--releaseβ removes all artifacts in thereleasedirectory. π₯--profilename β removes all artifacts in the directory with the given profile name.--target-dirdirectory β the directory for all generated artifacts and intermediate files. May also be specified 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. π--targettriple β clean for the specified target architecture. The flag may be specified multiple times. The default is the host architecture. The general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>.
Possible values, bestie:
- Any supported target in
rustc --print target-list. "host-tuple", which will internally be substituted by the host's target. This can be particularly useful if you're cross-compiling some crates, and don't want to specify your host's machine as a target (for instance, anxtaskin a shared project that may be worked on by many hosts).- A path to a custom target specification. See Custom Target Lookup Path
<https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path>for more information.
This may also be specified with the build.target config value <https://doc.rust-lang.org/cargo/reference/config.html>.
heads up! Note that specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. See the build cache <https://doc.rust-lang.org/cargo/reference/build-cache.html> documentation for more details. π§
π₯οΈ Display Options π₯οΈ
-v,--verboseβ use verbose output. May be specified twice for "very verbose" output, which includes extra output such as dependency warnings and build script output. May also be specified with theterm.verboseconfig value<https://doc.rust-lang.org/cargo/reference/config.html>. π£οΈ-q,--quietβ do not print cargo log messages. May also be specified with theterm.quietconfig value<https://doc.rust-lang.org/cargo/reference/config.html>. π€«--colorwhen β control when colored output is used. Valid values:auto(default): automatically detect if color support is available on the terminal.always: always display colors.never: never display colors.
May also be specified 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 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 the following 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. π
--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.
careful, bestie! Beware that 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 specified with the net.offline config value <https://doc.rust-lang.org/cargo/reference/config.html>.
--frozenβ equivalent to specifying both--lockedand--offline. βοΈ--lockfile-pathPATH β 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 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 lockfile into the provided PATH.
nightly only, no cap! 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 #14421<https://github.com/rust-lang/cargo/issues/14421>). π
π 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<https://rust-lang.github.io/rustup/overrides.html>for more information about 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<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.
nightly only again! 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 #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!! π«Ά This was CARGO-CLEAN(1) from the General Commands Manual, and yes, the footer is literally just the title again β iconic of it, honestly. π Go forth and clean your target directory. Periodt. πβ¨π¦
π¦ where this page comes from
- ubuntu jammy: cargo-1.91 1.91.1+dfsg~22.04-0ubuntu0.22.04.3 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.91 1.91.1+dfsg~24.04-0ubuntu0.24.04.2 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.91 1.91.1+dfsg~24.04-0ubuntu0.24.04.3 Β· Apache-2.0 WITH LLVM exception
- ubuntu questing: cargo-1.91 1.91.1+dfsg-0ubuntu3~25.10.1
- ubuntu resolute: cargo-1.91 1.91.1+dfsg-0ubuntu3 Β· 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