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