CARGO-CLEAN(1)

πŸ“¦ version 1.92.0, in ubuntu resolute

🧼 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 πŸ‘‘). See cargo-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 --verbose to display the actual files that would be deleted.
  • --doc β€” this option makes cargo clean remove only the doc directory in the target directory. Just the docs, nothing else. πŸŽ€
  • --release β€” removes all artifacts in the release directory. πŸ”₯
  • --profile name β€” removes all artifacts in the directory with the given profile name.
  • --target-dir directory β€” the directory for all generated artifacts and intermediate files. May also be specified with the CARGO_TARGET_DIR environment variable, or the build.target-dir config value <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to target in the root of the workspace. 🏠
  • --target triple β€” 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, an xtask in 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 the term.verbose config value <https://doc.rust-lang.org/cargo/reference/config.html>. πŸ—£οΈ
  • -q, --quiet β€” do not print cargo log messages. May also be specified with the term.quiet config value <https://doc.rust-lang.org/cargo/reference/config.html>. 🀫
  • --color when β€” 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-path path β€” path to the Cargo.toml file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory. πŸ”
  • --locked β€” asserts that the exact same dependencies and versions are used as when the existing Cargo.lock file 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 --locked and --offline. ❄️
  • --lockfile-path PATH β€” changes the path of the lockfile from the default (<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock (e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that providing --lockfile-path will 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-options flag 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 to cargo begins with +, it will be interpreted as a rustup toolchain name (such as +stable or +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 of KEY=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 example cargo -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-options flag to enable (see #10098 <https://github.com/rust-lang/cargo/issues/10098>). πŸŒ™
  • -h, --help β€” prints help information. πŸ†˜
  • -Z flag β€” unstable (nightly-only) flags to Cargo. Run cargo -Z help for 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 πŸ“

  1. Remove the entire target directory:
cargo clean
  1. Remove only the release artifacts:
cargo clean --release

πŸ‘€ SEE ALSO πŸ‘€

cargo(1), cargo-build(1)


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