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 --dry-run
28 Displays a summary of what would be deleted without deleting
29 anything. Use with --verbose to display the actual files that would
30 be deleted.
31
32 --doc
33 This option will cause cargo clean to remove only the doc directory
34 in the target directory.
35
36 --release
37 Remove all artifacts in the release directory.
38
39 --profile name
40 Remove all artifacts in the directory with the given profile name.
41
42 --target-dir directory
43 Directory for all generated artifacts and intermediate files. May
44 also be specified with the CARGO_TARGET_DIR environment variable,
45 or the build.target-dir config value
46 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
47 to target in the root of the workspace.
48
49 --target triple
50 Clean for the given architecture. The default is the host
51 architecture. The general format of the triple is
52 <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
53 a list of supported targets. This flag may be specified multiple
54 times.
55
56 This may also be specified with the build.target config value
57 <https://doc.rust-lang.org/cargo/reference/config.html>.
58
59 Note that specifying this flag makes Cargo run in a different mode
60 where the target artifacts are placed in a separate directory. See
61 the build cache
62 <https://doc.rust-lang.org/cargo/guide/build-cache.html>
63 documentation for more details.
64
65 Display Options
66 -v, --verbose
67 Use verbose output. May be specified twice for “very verbose”
68 output which includes extra output such as dependency warnings and
69 build script output. May also be specified with the term.verbose
70 config value
71 <https://doc.rust-lang.org/cargo/reference/config.html>.
72
73 -q, --quiet
74 Do not print cargo log messages. May also be specified with the
75 term.quiet config value
76 <https://doc.rust-lang.org/cargo/reference/config.html>.
77
78 --color when
79 Control when colored output is used. Valid values:
80
81 • auto (default): Automatically detect if color support is
82 available on the terminal.
83
84 • always: Always display colors.
85
86 • never: Never display colors.
87
88 May also be specified with the term.color config value
89 <https://doc.rust-lang.org/cargo/reference/config.html>.
90
91 Manifest Options
92 --manifest-path path
93 Path to the Cargo.toml file. By default, Cargo searches for the
94 Cargo.toml file in the current directory or any parent directory.
95
96 --frozen, --locked
97 Either of these flags requires that the Cargo.lock file is
98 up-to-date. If the lock file is missing, or it needs to be updated,
99 Cargo will exit with an error. The --frozen flag also prevents
100 Cargo from attempting to access the network to determine if it is
101 out-of-date.
102
103 These may be used in environments where you want to assert that the
104 Cargo.lock file is up-to-date (such as a CI build) or want to avoid
105 network access.
106
107 --offline
108 Prevents Cargo from accessing the network for any reason. Without
109 this flag, Cargo will stop with an error if it needs to access the
110 network and the network is not available. With this flag, Cargo
111 will attempt to proceed without the network if possible.
112
113 Beware that this may result in different dependency resolution than
114 online mode. Cargo will restrict itself to crates that are
115 downloaded locally, even if there might be a newer version as
116 indicated in the local copy of the index. See the cargo-fetch(1)
117 command to download dependencies before going offline.
118
119 May also be specified with the net.offline config value
120 <https://doc.rust-lang.org/cargo/reference/config.html>.
121
122 Common Options
123 +toolchain
124 If Cargo has been installed with rustup, and the first argument to
125 cargo begins with +, it will be interpreted as a rustup toolchain
126 name (such as +stable or +nightly). See the rustup documentation
127 <https://rust-lang.github.io/rustup/overrides.html> for more
128 information about how toolchain overrides work.
129
130 --config KEY=VALUE or PATH
131 Overrides a Cargo configuration value. The argument should be in
132 TOML syntax of KEY=VALUE, or provided as a path to an extra
133 configuration file. This flag may be specified multiple times. See
134 the command-line overrides section
135 <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
136 for more information.
137
138 -C PATH
139 Changes the current working directory before executing any
140 specified operations. This affects things like where cargo looks by
141 default for the project manifest (Cargo.toml), as well as the
142 directories searched for discovering .cargo/config.toml, for
143 example. This option must appear before the command name, for
144 example cargo -C path/to/my-project build.
145
146 This option is only available on the nightly channel
147 <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
148 requires the -Z unstable-options flag to enable (see #10098
149 <https://github.com/rust-lang/cargo/issues/10098>).
150
151 -h, --help
152 Prints help information.
153
154 -Z flag
155 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
156 details.
157
159 See the reference
160 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
161 for details on environment variables that Cargo reads.
162
164 • 0: Cargo succeeded.
165
166 • 101: Cargo failed to complete.
167
169 1. Remove the entire target directory:
170
171 cargo clean
172
173 2. Remove only the release artifacts:
174
175 cargo clean --release
176
178 cargo(1), cargo-build(1)
179
180
181
182 CARGO-CLEAN(1)