CARGO-CLEAN(1)
π§Ήβ¨ CARGO-CLEAN β¨π§Ή
General Commands Manual energy, but make it a group chat π
okay so bestie, you know how your target/ directory slowly turns into a landfill of build junk? this is the page for that. it's the cargo clean manual, it lives in the General Commands Manual, and honestly deleting things is self-care. periodt. π«Ά
πΈ NAME πΈ
cargo-clean β Remove generated artifacts ποΈβ¨
π¦ SYNOPSIS π¦
cargo clean [options]
π DESCRIPTION π
So what it does is: it removes the artifacts from the target directory that Cargo has generated in the past. bye bye build junk π
And here's the main character moment β with no options, cargo clean will delete the entire target directory. all of it. every last crumb. iconic behavior fr fr π₯
π OPTIONS π
π¦ Package Selection π¦
Quick vibe check: when no packages are selected, all packages and all dependencies in the workspace get cleaned. everybody's getting a glow-up, no exceptions π
-p,--packagespecβ¦ β clean only the specified packages. this flag may be specified multiple times. for the SPEC format, go peek atcargo-pkgid(1)π--workspaceβ clean artifacts of the workspace members. just the members, bestie π§
π§Ό Clean Options π§Ό
--dry-runβ displays a summary of what would be deleted, without deleting anything. use it with--verboseto display the actual files that would be deleted. it's giving "window shopping" ποΈ--docβ this option will causecargo cleanto remove only thedocdirectory in thetargetdirectory. docs only, no touchy the rest π--releaseβ remove all artifacts in thereleasedirectory. production girlies, this one's for you π--profilename β remove all artifacts in the directory with the given profile name.--target-dirdirectory β directory for all generated artifacts and intermediate files. may also be specified with theCARGO_TARGET_DIRenvironment variable, or thebuild.target-dirconfig value athttps://doc.rust-lang.org/cargo/reference/config.html. defaults totargetin the root of the workspace π―--targettriple β clean for the specified target architecture. 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:
- 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 at
https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-pathfor more information.
This may also be specified with the build.target config value at https://doc.rust-lang.org/cargo/reference/config.html.
heads up bestie: 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 documentation at https://doc.rust-lang.org/cargo/reference/build-cache.html for more details. don't say I didn't warn you π
π£οΈ 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 athttps://doc.rust-lang.org/cargo/reference/config.html. spill the tea β-q,--quietβ do not print cargo log messages. may also be specified with theterm.quietconfig value athttps://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 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. it'll find it, she's resourceful π--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. no surprises allowed, we love a predictable queen π
--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 specified 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, slay π
π 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 athttps://rust-lang.github.io/rustup/overrides.htmlfor 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 athttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesfor 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. order matters, bestie π
this option is only available on the nightly channel athttps://doc.rust-lang.org/book/appendix-07-nightly-rust.htmland requires the-Z unstable-optionsflag to enable (see#10098athttps://github.com/rust-lang/cargo/issues/10098). nightly girlies only π
-h,--helpβ prints help information. π-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 details on environment variables that Cargo reads. that's where the lore lives πβ¨
β EXIT STATUS β
0: Cargo succeeded. π101: Cargo failed to complete. π
π EXAMPLES π
- Remove the entire
targetdirectory:
cargo clean
- Remove only the release artifacts:
cargo clean --release
π₯ SEE ALSO π₯
okay that's the whole page, you ate that π«Ά this was CARGO-CLEAN(1) straight out of the General Commands Manual β same title at the top and at the bottom, that's the whole footer, no extra version or date to report, just vibes and a very clean target/ directory. go forth and delete responsibly bestie πβ¨π§Ή
π¦ where this page comes from
- alpine 3.24: cargo-doc 1.96.1-r0 Β· Apache-2.0 OR MIT
- alpine 3.24: chromium-cargo-doc 1.97.0-r0 Β· Apache-2.0 OR MIT
- centos-stream 10: cargo 1.99.1-1.el10 Β· (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- centos-stream 9: cargo 1.99.1-1.el9 Β· (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- debian bookworm: cargo-web 1.96.0+dfsg1-1~deb12u2 Β· MIT OR Apache-2.0
- debian trixie: cargo-web 1.96.0+dfsg1-1~deb13u1+b1 Β· MIT OR Apache-2.0
- fedora 43: cargo 1.98.1-1.fc43
- fedora 43: cargo 1.99.0-1.fc43
- fedora 43: cargo 1.99.1-2.fc43 Β· (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- fedora 44: cargo 1.94.1-1.fc44 Β· (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- fedora 44: cargo 1.98.1-1.fc44
- fedora 44: cargo 1.99.0-1.fc44
- fedora 44: cargo 1.99.1-2.fc44 Β· (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- nixos 26.05: cargo 1.95.0
- opensuse-leap 16.0: cargo1.94 1.94.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.94 1.94.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.94 1.94.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.94 1.94.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.95 1.95.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.95 1.95.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.95 1.95.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.95 1.95.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.96 1.96.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.96 1.96.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.96 1.96.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.96 1.96.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.97 1.97.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.97 1.97.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.97 1.97.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.97 1.97.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.98 1.98.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.98 1.98.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.98 1.98.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.98 1.98.0-160000.1.1 Β· Apache-2.0 OR MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms