1rm(1) User Commands rm(1)
2
3
4
6 rm, rmdir - remove directory entries
7
9 /usr/bin/rm [-f] [-i] file...
10
11
12 /usr/bin/rm -rR [-f] [-i] dirname... [file]...
13
14
15 /usr/xpg4/bin/rm [-fiRr] file...
16
17
18 /usr/bin/rmdir [-ps] dirname...
19
20
21 ksh93
22 /usr/bin/rmdir [-eps] dirname...
23
24
26 /usr/bin/rm /usr/xpg4/bin/rm
27 The rm utility removes the directory entry specified by each file argu‐
28 ment. If a file has no write permission and the standard input is a
29 terminal, the full set of permissions (in octal) for the file are
30 printed followed by a question mark. This is a prompt for confirmation.
31 If the answer is affirmative, the file is deleted, otherwise the file
32 remains.
33
34
35 If file is a symbolic link, the link is removed, but the file or direc‐
36 tory to which it refers is not deleted. Users do not need write permis‐
37 sion to remove a symbolic link, provided they have write permissions in
38 the directory.
39
40
41 If multiple files are specified and removal of a file fails for any
42 reason, rm writes a diagnostic message to standard error, do nothing
43 more to the current file, and go on to any remaining files.
44
45
46 If the standard input is not a terminal, the utility operates as if the
47 -f option is in effect.
48
49 /usr/bin/rmdir
50 The rmdir utility removes the directory entry specified by each dirname
51 operand, which must refer to an empty directory.
52
53
54 Directories are processed in the order specified. If a directory and a
55 subdirectory of that directory are specified in a single invocation of
56 rmdir, the subdirectory must be specified before the parent directory
57 so that the parent directory is empty when rmdir tries to remove it.
58
59 ksh93
60 The rmdir built-in in ksh93 is associated with the /bin and /usr/bin
61 paths. It is invoked when rmdir is executed without a pathname prefix
62 and the pathname search finds a /bin/rmdir or /usr/bin/rmdir exe‐
63 cutable.
64
65
66 rmdir deletes each given directory. The directory must be empty and
67 contain no entries other than . or ... If a directory and a subdirec‐
68 tory of that directory are specified as operands, the subdirectory must
69 be specified before the parent, so that the parent directory is empty
70 when rmdir attempts to remove it.
71
73 The following options are supported for /usr/bin/rm and
74 /usr/xpg4/bin/rm:
75
76 -r Recursively removes directories and subdirectories in the argu‐
77 ment list. The directory is emptied of files and removed. The
78 user is normally prompted for removal of any write-protected
79 files which the directory contains. The write-protected files are
80 removed without prompting, however, if the -f option is used, or
81 if the standard input is not a terminal and the -i option is not
82 used.
83
84 Symbolic links that are encountered with this option is not tra‐
85 versed.
86
87 If the removal of a non-empty, write-protected directory is
88 attempted, the utility always fails (even if the -f option is
89 used), resulting in an error message.
90
91
92 -R Same as -r option.
93
94
95 /usr/bin/rm
96 The following options are supported for /usr/bin/rm only:
97
98 -f Removes all files (whether write-protected or not) in a directory
99 without prompting the user. In a write-protected directory, how‐
100 ever, files are never removed (whatever their permissions are),
101 but no messages are displayed. If the removal of a write-pro‐
102 tected directory is attempted, this option does not suppress an
103 error message.
104
105
106 -i Interactive. With this option, rm prompts for confirmation before
107 removing any files. It overrides the -f option and remains in
108 effect even if the standard input is not a terminal.
109
110
111 /usr/xpg4/bin/rm
112 The following options are supported for /usr/xpg4/bin/rm only:
113
114 -f Does not prompt for confirmation. Does not write diagnostic mes‐
115 sages or modify the exit status in the case of non-existent oper‐
116 ands. Any previous occurrences of the -i option is ignored.
117
118
119 -i Prompts for confirmation. Any occurrences of the -f option is
120 ignored.
121
122
123 /usr/bin/rmdir
124 The following options are supported for /usr/bin/rmdir only:
125
126 -p Allows users to remove the directory dirname and its parent
127 directories which become empty. A message is printed to standard
128 error if all or part of the path could not be removed.
129
130
131 -s Suppresses the message printed on the standard error when -p is
132 in effect.
133
134
135 ksh93
136 The following options are supported for the rmdir built-in for ksh93:
137
138 -e Ignore each non-empty directory failure.
139 --ignore-fail-on-non-empty
140
141 -p Remove each explicit directory argument
142 --parents directory that becomes empty after its
143 child directories are removed.
144
145
146 -s Suppress the message printed on the stan‐
147 --suppress dard error when -p is in effect.
148
149
151 The following operands are supported:
152
153 file Specifies the pathname of a directory entry to be removed.
154
155
156 dirname Specifies the pathname of an empty directory to be removed.
157
158
160 See largefile(5) for the description of the behavior of rm and rmdir
161 when encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
162
164 The following examples are valid for the commands shown.
165
166 /usr/bin/rm, /usr/xpg4/bin/rm
167 Example 1 Removing Directories
168
169
170 The following command removes the directory entries a.out and core:
171
172
173 example% rm a.out core
174
175
176
177 Example 2 Removing a Directory without Prompting
178
179
180 The following command removes the directory junk and all its contents,
181 without prompting:
182
183
184 example% rm -rf junk
185
186
187
188 /usr/bin/rmdir
189 Example 3 Removing Empty Directories
190
191
192 If a directory a in the current directory is empty, except that it con‐
193 tains a directory b, and a/b is empty except that it contains a direc‐
194 tory c, the following command removes all three directories:
195
196
197 example% rmdir -p a/b/c
198
199
200
202 See environ(5) for descriptions of the following environment variables
203 that affect the execution of rm and rmdir: LANG, LC_ALL, LC_COLLATE,
204 LC_CTYPE, LC_MESSAGES, and NLSPATH.
205
206
207 Affirmative responses are processed using the extended regular expres‐
208 sion defined for the yesexpr keyword in the LC_MESSAGES category of the
209 user's locale. The locale specified in the LC_COLLATE category defines
210 the behavior of ranges, equivalence classes, and multi-character col‐
211 lating elements used in the expression defined for yesexpr. The locale
212 specified in LC_CTYPE determines the locale for interpretation of
213 sequences of bytes of text data a characters, the behavior of character
214 classes used in the expression defined for the yesexpr. See locale(5).
215
217 The following exit values are returned:
218
219 0 If the -f option was not specified, all the named directory
220 entries were removed; otherwise, all the existing named directory
221 entries were removed.
222
223
224 >0 An error occurred.
225
226
227 ksh93
228 The following exit values are returned:
229
230 0 Successful completion. All directories deleted successfully.
231
232
233 >0 An error occurred. One or more directories could not be deleted.
234
235
237 See attributes(5) for descriptions of the following attributes:
238
239 /usr/bin/rm, /usr/bin/rmdir
240 ┌─────────────────────────────┬─────────────────────────────┐
241 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
242 ├─────────────────────────────┼─────────────────────────────┤
243 │Availability │SUNWcsu │
244 ├─────────────────────────────┼─────────────────────────────┤
245 │CSI │Enabled │
246 └─────────────────────────────┴─────────────────────────────┘
247
248 /usr/xpg4/bin/rm
249 ┌─────────────────────────────┬─────────────────────────────┐
250 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
251 ├─────────────────────────────┼─────────────────────────────┤
252 │Availability │SUNWxcu4 │
253 ├─────────────────────────────┼─────────────────────────────┤
254 │CSI │Enabled │
255 ├─────────────────────────────┼─────────────────────────────┤
256 │Interface Stability │Committed │
257 ├─────────────────────────────┼─────────────────────────────┤
258 │Standard │See standards(5). │
259 └─────────────────────────────┴─────────────────────────────┘
260
261 ksh93
262 ┌─────────────────────────────┬─────────────────────────────┐
263 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
264 ├─────────────────────────────┼─────────────────────────────┤
265 │Availability │SUNWcsu │
266 ├─────────────────────────────┼─────────────────────────────┤
267 │Interface Stability │See below. │
268 └─────────────────────────────┴─────────────────────────────┘
269
270
271 The ksh93 built-in binding to /bin and /usr/bin is Volatile. The built-
272 in interfaces are Uncommitted.
273
275 ksh93(1), rmdir(2), rmdir(2), unlink(2), attributes(5), environ(5),
276 largefile(5), standards(5)
277
279 All messages are generally self-explanatory.
280
281
282 It is forbidden to remove the files "." and ".." in order to avoid the
283 consequences of inadvertently doing something like the following:
284
285 example% rm -r .*
286
287
288
289
290 It is forbidden to remove the file "/" in order to avoid the conse‐
291 quences of inadvertently doing something like:
292
293 example% rm -rf $x/$y
294
295
296
297
298 or
299
300 example% rm -rf /$y
301
302
303
304
305 when $x and $y expand to empty strings.
306
308 A − permits the user to mark explicitly the end of any command line
309 options, allowing rm to recognize file arguments that begin with a −.
310 As an aid to BSD migration, rm accepts −− as a synonym for −. This
311 migration aid may disappear in a future release. If a −− and a − both
312 appear on the same command line, the second is interpreted as a file.
313
314
315
316SunOS 5.11 20 Nov 2007 rm(1)