1CARGO-CLEAN(1) General Commands Manual CARGO-CLEAN(1)
2
3
4
6 cargo-clean - Remove generated artifacts
7
9 cargo clean [options]
10
12 Remove artifacts from the target directory that Cargo has generated in
13 the past.
14
15 With no options, cargo clean will delete the entire target directory.
16
18 Package Selection
19 When no packages are selected, all packages and all dependencies in the
20 workspace are cleaned.
21
22 -p spec..., --package spec...
23 Clean only the specified packages. This flag may be specified
24 multiple times. See cargo-pkgid(1) for the SPEC format.
25
26 Clean Options
27 --doc
28 This option will cause cargo clean to remove only the doc directory
29 in the target directory.
30
31 --release
32 Remove all artifacts in the release directory.
33
34 --profile name
35 Remove all artifacts in the directory with the given profile name.
36
37 --target-dir directory
38 Directory for all generated artifacts and intermediate files. May
39 also be specified with the CARGO_TARGET_DIR environment variable,
40 or the build.target-dir config value
41 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
42 to target in the root of the workspace.
43
44 --target triple
45 Clean for the given architecture. The default is the host
46 architecture. The general format of the triple is
47 <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
48 a list of supported targets. This flag may be specified multiple
49 times.
50
51 This may also be specified with the build.target config value
52 <https://doc.rust-lang.org/cargo/reference/config.html>.
53
54 Note that specifying this flag makes Cargo run in a different mode
55 where the target artifacts are placed in a separate directory. See
56 the build cache
57 <https://doc.rust-lang.org/cargo/guide/build-cache.html>
58 documentation for more details.
59
60 Display Options
61 -v, --verbose
62 Use verbose output. May be specified twice for "very verbose"
63 output which includes extra output such as dependency warnings and
64 build script output. May also be specified with the term.verbose
65 config value
66 <https://doc.rust-lang.org/cargo/reference/config.html>.
67
68 -q, --quiet
69 Do not print cargo log messages. May also be specified with the
70 term.quiet config value
71 <https://doc.rust-lang.org/cargo/reference/config.html>.
72
73 --color when
74 Control when colored output is used. Valid values:
75
76 • auto (default): Automatically detect if color support is
77 available on the terminal.
78
79 • always: Always display colors.
80
81 • never: Never display colors.
82
83 May also be specified with the term.color config value
84 <https://doc.rust-lang.org/cargo/reference/config.html>.
85
86 Manifest Options
87 --manifest-path path
88 Path to the Cargo.toml file. By default, Cargo searches for the
89 Cargo.toml file in the current directory or any parent directory.
90
91 --frozen, --locked
92 Either of these flags requires that the Cargo.lock file is
93 up-to-date. If the lock file is missing, or it needs to be updated,
94 Cargo will exit with an error. The --frozen flag also prevents
95 Cargo from attempting to access the network to determine if it is
96 out-of-date.
97
98 These may be used in environments where you want to assert that the
99 Cargo.lock file is up-to-date (such as a CI build) or want to avoid
100 network access.
101
102 --offline
103 Prevents Cargo from accessing the network for any reason. Without
104 this flag, Cargo will stop with an error if it needs to access the
105 network and the network is not available. With this flag, Cargo
106 will attempt to proceed without the network if possible.
107
108 Beware that this may result in different dependency resolution than
109 online mode. Cargo will restrict itself to crates that are
110 downloaded locally, even if there might be a newer version as
111 indicated in the local copy of the index. See the cargo-fetch(1)
112 command to download dependencies before going offline.
113
114 May also be specified with the net.offline config value
115 <https://doc.rust-lang.org/cargo/reference/config.html>.
116
117 Common Options
118 +toolchain
119 If Cargo has been installed with rustup, and the first argument to
120 cargo begins with +, it will be interpreted as a rustup toolchain
121 name (such as +stable or +nightly). See the rustup documentation
122 <https://rust-lang.github.io/rustup/overrides.html> for more
123 information about how toolchain overrides work.
124
125 --config KEY=VALUE or PATH
126 Overrides a Cargo configuration value. The argument should be in
127 TOML syntax of KEY=VALUE, or provided as a path to an extra
128 configuration file. This flag may be specified multiple times. See
129 the command-line overrides section
130 <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
131 for more information.
132
133 -h, --help
134 Prints help information.
135
136 -Z flag
137 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
138 details.
139
141 See the reference
142 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
143 for details on environment variables that Cargo reads.
144
146 • 0: Cargo succeeded.
147
148 • 101: Cargo failed to complete.
149
151 1. Remove the entire target directory:
152
153 cargo clean
154
155 2. Remove only the release artifacts:
156
157 cargo clean --release
158
160 cargo(1), cargo-build(1)
161
162
163
164 CARGO-CLEAN(1)