CARGO-CLEAN(1)

πŸ“¦ version 1.83.0, in ubuntu jammy, ubuntu noble

okay so bestie πŸ’– your target directory is giving hoarder house and it's time for a cleanse. this is the cargo-clean page from the General Commands Manual (section 1), and it's literally the glow-up ritual your project has been begging for. ✨

🌸 NAME 🌸

cargo-clean β€” remove generated artifacts 🧹✨

πŸ¦‹ SYNOPSIS πŸ¦‹

cargo clean [options]

πŸ’… DESCRIPTION πŸ’…

Removes artifacts from the target directory that Cargo generated in the past. it's giving spring cleaning, it's giving "we don't talk about that old build anymore." πŸ’€

⚠️ heads up bestie: with no options at all, cargo clean will delete the entire target directory. not some of it. all of it. gone. periodt. 😭

✨ OPTIONS ✨

πŸŽ€ Package Selection πŸŽ€

When no packages are selected, all packages and all dependencies in the workspace get cleaned. so like, everything, girl.

  • -p spec…, --package spec… β€” only clean the packages you name. you can drop this flag multiple times if you wanna list several. peep cargo-pkgid(1) for the SPEC format. πŸ’–

🧹 Clean Options 🧹

  • --dry-run β€” shows you a lil summary of what would get deleted without deleting a single thing. the way that… you can pair it with --verbose to see the actual files that would be yeeted. πŸ‘€
  • --doc β€” makes cargo clean remove only the doc directory inside the target directory. just the docs, nothing else.
  • --release β€” nukes all artifacts in the release directory. πŸ”₯
  • --profile name β€” nukes all artifacts in the directory with the profile name you hand it.
  • --target-dir directory β€” where all generated artifacts and intermediate files live. you can also set this 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 architecture you name. the default is the host architecture. general format of the triple is <arch><sub>-<vendor>-<sys>-<abi>. run rustc --print target-list to see the 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).

ngl 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/reference/build-cache.html) for more details.

🌈 Display Options 🌈

  • -v, --verbose β€” verbose output. specify it twice for "very verbose" output, which includes extra output like dependency warnings and build script output. you can also set this with the term.verbose config value (https://doc.rust-lang.org/cargo/reference/config.html).
  • -q, --quiet β€” do not print cargo log messages. silent mode, main character energy. you can also set this with the term.quiet config value (https://doc.rust-lang.org/cargo/reference/config.html).
  • --color when β€” controls when colored output gets used. valid values:
    • auto (default): automatically detect if color support is available on the terminal.
    • always: always display colors. 🌈
    • never: never display colors.

you can also set this 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 Cargo.toml 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 these scenarios arises:
    • the lock file is missing.
    • Cargo attempted to change the lock file due to a different dependency resolution.

it can be used in environments where deterministic builds are desired, like 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 isn't 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.

you can also set this with the net.offline config value (https://doc.rust-lang.org/cargo/reference/config.html).

  • --frozen β€” equivalent to specifying both --locked and --offline. two-for-one deal. πŸ’…
  • --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 the 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 the lockfile into the provided PATH.
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 was installed with rustup, and the first argument to cargo begins with +, it gets 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.
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 the environment variables that Cargo reads. iykyk.

πŸ’€ EXIT STATUS πŸ’€

  • 0: Cargo succeeded. slay. πŸ‘‘
  • 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)


okay that's the whole page bestie πŸ’– it's CARGO-CLEAN(1) out of the General Commands Manual, and the footer line was literally just CARGO-CLEAN(1) again β€” like, the manual said its own name twice, iconic. πŸŽ€βœ¨ go forth and clean, and remember: the facts stayed exactly the same, only the vibe got upgraded. πŸ’…

πŸ“¦ where this page comes from