1RM(1P) POSIX Programmer's Manual RM(1P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 rm — remove directory entries
13
15 rm [-iRr] file...
16
17 rm -f [-iRr] [file...]
18
20 The rm utility shall remove the directory entry specified by each file
21 argument.
22
23 If either of the files dot or dot-dot are specified as the basename
24 portion of an operand (that is, the final pathname component) or if an
25 operand resolves to the root directory, rm shall write a diagnostic
26 message to standard error and do nothing more with such operands.
27
28 For each file the following steps shall be taken:
29
30 1. If the file does not exist:
31
32 a. If the -f option is not specified, rm shall write a diagnostic
33 message to standard error.
34
35 b. Go on to any remaining files.
36
37 2. If file is of type directory, the following steps shall be taken:
38
39 a. If neither the -R option nor the -r option is specified, rm
40 shall write a diagnostic message to standard error, do nothing
41 more with file, and go on to any remaining files.
42
43 b. If file is an empty directory, rm may skip to step 2d. If the
44 -f option is not specified, and either the permissions of file
45 do not permit writing and the standard input is a terminal or
46 the -i option is specified, rm shall write a prompt to standard
47 error and read a line from the standard input. If the response
48 is not affirmative, rm shall do nothing more with the current
49 file and go on to any remaining files.
50
51 c. For each entry contained in file, other than dot or dot-dot,
52 the four steps listed here (1 to 4) shall be taken with the
53 entry as if it were a file operand. The rm utility shall not
54 traverse directories by following symbolic links into other
55 parts of the hierarchy, but shall remove the links themselves.
56
57 d. If the -i option is specified, rm shall write a prompt to stan‐
58 dard error and read a line from the standard input. If the
59 response is not affirmative, rm shall do nothing more with the
60 current file, and go on to any remaining files.
61
62 3. If file is not of type directory, the -f option is not specified,
63 and either the permissions of file do not permit writing and the
64 standard input is a terminal or the -i option is specified, rm
65 shall write a prompt to the standard error and read a line from the
66 standard input. If the response is not affirmative, rm shall do
67 nothing more with the current file and go on to any remaining
68 files.
69
70 4. If the current file is a directory, rm shall perform actions equiv‐
71 alent to the rmdir() function defined in the System Interfaces vol‐
72 ume of POSIX.1‐2017 called with a pathname of the current file used
73 as the path argument. If the current file is not a directory, rm
74 shall perform actions equivalent to the unlink() function defined
75 in the System Interfaces volume of POSIX.1‐2017 called with a path‐
76 name of the current file used as the path argument.
77
78 If this fails for any reason, rm shall write a diagnostic message
79 to standard error, do nothing more with the current file, and go on
80 to any remaining files.
81
82 The rm utility shall be able to descend to arbitrary depths in a file
83 hierarchy, and shall not fail due to path length limitations (unless an
84 operand specified by the user exceeds system limitations).
85
87 The rm utility shall conform to the Base Definitions volume of
88 POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
89
90 The following options shall be supported:
91
92 -f Do not prompt for confirmation. Do not write diagnostic mes‐
93 sages or modify the exit status in the case of no file oper‐
94 ands, or in the case of operands that do not exist. Any pre‐
95 vious occurrences of the -i option shall be ignored.
96
97 -i Prompt for confirmation as described previously. Any previous
98 occurrences of the -f option shall be ignored.
99
100 -R Remove file hierarchies. See the DESCRIPTION.
101
102 -r Equivalent to -R.
103
105 The following operand shall be supported:
106
107 file A pathname of a directory entry to be removed.
108
110 The standard input shall be used to read an input line in response to
111 each prompt specified in the STDOUT section. Otherwise, the standard
112 input shall not be used.
113
115 None.
116
118 The following environment variables shall affect the execution of rm:
119
120 LANG Provide a default value for the internationalization vari‐
121 ables that are unset or null. (See the Base Definitions vol‐
122 ume of POSIX.1‐2017, Section 8.2, Internationalization Vari‐
123 ables for the precedence of internationalization variables
124 used to determine the values of locale categories.)
125
126 LC_ALL If set to a non-empty string value, override the values of
127 all the other internationalization variables.
128
129 LC_COLLATE
130 Determine the locale for the behavior of ranges, equivalence
131 classes, and multi-character collating elements used in the
132 extended regular expression defined for the yesexpr locale
133 keyword in the LC_MESSAGES category.
134
135 LC_CTYPE Determine the locale for the interpretation of sequences of
136 bytes of text data as characters (for example, single-byte as
137 opposed to multi-byte characters in arguments) and the behav‐
138 ior of character classes within regular expressions used in
139 the extended regular expression defined for the yesexpr
140 locale keyword in the LC_MESSAGES category.
141
142 LC_MESSAGES
143 Determine the locale used to process affirmative responses,
144 and the locale used to affect the format and contents of
145 diagnostic messages and prompts written to standard error.
146
147 NLSPATH Determine the location of message catalogs for the processing
148 of LC_MESSAGES.
149
151 Default.
152
154 Not used.
155
157 Prompts shall be written to standard error under the conditions speci‐
158 fied in the DESCRIPTION and OPTIONS sections. The prompts shall contain
159 the file pathname, but their format is otherwise unspecified. The stan‐
160 dard error also shall be used for diagnostic messages.
161
163 None.
164
166 None.
167
169 The following exit values shall be returned:
170
171 0 Each directory entry was successfully removed, unless its removal
172 was canceled by a non-affirmative response to a prompt for con‐
173 firmation.
174
175 >0 An error occurred.
176
178 Default.
179
180 The following sections are informative.
181
183 The rm utility is forbidden to remove the names dot and dot-dot in
184 order to avoid the consequences of inadvertently doing something like:
185
186
187 rm -r .*
188
189 Some implementations do not permit the removal of the last link to an
190 executable binary file that is being executed; see the [EBUSY] error in
191 the unlink() function defined in the System Interfaces volume of
192 POSIX.1‐2017. Thus, the rm utility can fail to remove such files.
193
194 The -i option causes rm to prompt and read the standard input even if
195 the standard input is not a terminal, but in the absence of -i the mode
196 prompting is not done when the standard input is not a terminal.
197
199 1. The following command:
200
201
202 rm a.out core
203
204 removes the directory entries: a.out and core.
205
206 2. The following command:
207
208
209 rm -Rf junk
210
211 removes the directory junk and all its contents, without prompting.
212
214 For absolute clarity, paragraphs (2b) and (3) in the DESCRIPTION of rm
215 describing the behavior when prompting for confirmation, should be
216 interpreted in the following manner:
217
218
219 if ((NOT f_option) AND
220 ((not_writable AND input_is_terminal) OR i_option))
221
222 The exact format of the interactive prompts is unspecified. Only the
223 general nature of the contents of prompts are specified because imple‐
224 mentations may desire more descriptive prompts than those used on his‐
225 torical implementations. Therefore, an application not using the -f
226 option, or using the -i option, relies on the system to provide the
227 most suitable dialog directly with the user, based on the behavior
228 specified.
229
230 The -r option is historical practice on all known systems. The synonym
231 -R option is provided for consistency with the other utilities in this
232 volume of POSIX.1‐2017 that provide options requesting recursive
233 descent through the file hierarchy.
234
235 The behavior of the -f option in historical versions of rm is inconsis‐
236 tent. In general, along with ``forcing'' the unlink without prompting
237 for permission, it always causes diagnostic messages to be suppressed
238 and the exit status to be unmodified for nonexistent operands and files
239 that cannot be unlinked. In some versions, however, the -f option sup‐
240 presses usage messages and system errors as well. Suppressing such
241 messages is not a service to either shell scripts or users.
242
243 It is less clear that error messages regarding files that cannot be
244 unlinked (removed) should be suppressed. Although this is historical
245 practice, this volume of POSIX.1‐2017 does not permit the -f option to
246 suppress such messages.
247
248 When given the -r and -i options, historical versions of rm prompt the
249 user twice for each directory, once before removing its contents and
250 once before actually attempting to delete the directory entry that
251 names it. This allows the user to ``prune'' the file hierarchy walk.
252 Historical versions of rm were inconsistent in that some did not do the
253 former prompt for directories named on the command line and others had
254 obscure prompting behavior when the -i option was specified and the
255 permissions of the file did not permit writing. The POSIX Shell and
256 Utilities rm differs little from historic practice, but does require
257 that prompts be consistent. Historical versions of rm were also incon‐
258 sistent in that prompts were done to both standard output and standard
259 error. This volume of POSIX.1‐2017 requires that prompts be done to
260 standard error, for consistency with cp and mv, and to allow historical
261 extensions to rm that provide an option to list deleted files on stan‐
262 dard output.
263
264 The rm utility is required to descend to arbitrary depths so that any
265 file hierarchy may be deleted. This means, for example, that the rm
266 utility cannot run out of file descriptors during its descent (that is,
267 if the number of file descriptors is limited, rm cannot be implemented
268 in the historical fashion where one file descriptor is used per direc‐
269 tory level). Also, rm is not permitted to fail because of path length
270 restrictions, unless an operand specified by the user is longer than
271 {PATH_MAX}.
272
273 The rm utility removes symbolic links themselves, not the files they
274 refer to, as a consequence of the dependence on the unlink() function‐
275 ality, per the DESCRIPTION. When removing hierarchies with -r or -R,
276 the prohibition on following symbolic links has to be made explicit.
277
279 None.
280
282 rmdir
283
284 The Base Definitions volume of POSIX.1‐2017, Chapter 8, Environment
285 Variables, Section 12.2, Utility Syntax Guidelines
286
287 The System Interfaces volume of POSIX.1‐2017, remove(), rmdir(),
288 unlink()
289
291 Portions of this text are reprinted and reproduced in electronic form
292 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
293 table Operating System Interface (POSIX), The Open Group Base Specifi‐
294 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
295 Electrical and Electronics Engineers, Inc and The Open Group. In the
296 event of any discrepancy between this version and the original IEEE and
297 The Open Group Standard, the original IEEE and The Open Group Standard
298 is the referee document. The original Standard can be obtained online
299 at http://www.opengroup.org/unix/online.html .
300
301 Any typographical or formatting errors that appear in this page are
302 most likely to have been introduced during the conversion of the source
303 files to man page format. To report such errors, see https://www.ker‐
304 nel.org/doc/man-pages/reporting_bugs.html .
305
306
307
308IEEE/The Open Group 2017 RM(1P)