xref: /illumos-gate/usr/src/man/man1/rm.1 (revision a48ca82f1984529f9cbef045f39cd6efa1be7713)
1'\" te
2.\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved
3.\" Copyright 1989 AT&T
4.\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
5.\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
6.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
7.\" http://www.opengroup.org/bookstore/.
8.\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
9.\" Copyright 2017 Joyent, Inc.
10.\"  This notice shall appear on any product containing this material.
11.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
12.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
13.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
14.Dd July 3, 2017
15.Dt RM 1
16.Os
17.Sh NAME
18.Nm rm ,
19.Nm rmdir
20.Nd remove directory entries
21.Sh SYNOPSIS
22.Nm /usr/bin/rm
23.Op Fl f
24.Op Fl i
25.Ar
26.Pp
27.Nm /usr/bin/rm
28.Fl rR
29.Op Fl f
30.Op Fl i
31.Ar dirname ...
32.Op Ar file ...
33.Pp
34.Nm /usr/xpg4/bin/rm
35.Op Fl fiRr
36.Ar
37.Pp
38.Nm /usr/bin/rmdir
39.Op Fl ps
40.Ar dirname
41.Ss "ksh93"
42.Nm /usr/bin/rmdir
43.Op Fl eps
44.Ar dirname ...
45.Sh DESCRIPTION
46.Ss "/usr/bin/rm /usr/xpg4/bin/rm"
47The
48.Nm rm
49utility removes the directory entry specified by each
50.Ar file
51argument.
52If a file has no write permission and the standard input is a terminal, the
53full set of permissions (in octal) for the file are printed followed by a
54question mark.
55This is a prompt for confirmation.
56If the answer is affirmative, the file is deleted, otherwise the file remains.
57.Pp
58If
59.Ar file
60is a symbolic link, the link is removed, but the file or directory to which it
61refers is not deleted.
62Users do not need write permission to remove a symbolic link, provided they
63have write permissions in the directory.
64.Pp
65If multiple
66.Ar file Ns s
67are specified and removal of a
68.Ar file
69fails for any reason,
70.Nm rm
71writes a diagnostic message to standard error, do nothing more to the current
72.Ar file ,
73and go on to any remaining
74.Ar file Ns s .
75.Pp
76If the standard input is not a terminal, the utility operates as if the
77.Fl f
78option is in effect.
79.Ss "/usr/bin/rmdir"
80The
81.Nm rmdir
82utility removes the directory entry specified by each
83.Ar dirname
84operand, which must refer to an empty directory.
85.Pp
86Directories are processed in the order specified.
87If a directory and a subdirectory of that directory are specified in a single
88invocation of
89.Nm rmdir ,
90the subdirectory must be specified before the parent directory so that the
91parent directory is empty when
92.Nm rmdir
93tries to remove it.
94.Ss "ksh93"
95The
96.Nm rmdir
97built-in in
98.Nm ksh93
99is associated with the
100.Pa /bin
101and
102.Pa /usr/bin
103paths.
104It is invoked when
105.Nm rmdir
106is executed without a pathname prefix and the pathname search finds a
107.Pa /bin/rmdir
108or
109.Pa /usr/bin/rmdir
110executable.
111.Pp
112.Nm rmdir
113deletes each given directory.
114The directory must be empty and contain no entries other than
115.Pa \&.
116or
117.Pa .. .
118If a directory and a
119subdirectory of that directory are specified as operands, the subdirectory must
120be specified before the parent, so that the parent directory is empty when
121.Nm rmdir
122attempts to remove it.
123.Sh OPTIONS
124The following options are supported for
125.Nm /usr/bin/rm
126and
127.Nm /usr/xpg4/bin/rm :
128.Bl -hang
129.It Fl r
130Recursively removes directories and subdirectories in the argument list.
131The directory is emptied of files and removed.
132The user is normally prompted for removal of any write-protected files which
133the directory contains.
134The write-protected files are removed without prompting, however, if the
135.Fl f
136option is used, or if the standard input is not a terminal and the
137.Fl i
138option is not used.
139.Pp
140Symbolic links that are encountered with this option is not traversed.
141.Pp
142If the removal of a non-empty, write-protected directory is attempted, the
143utility always fails (even if the
144.Fl f
145option is used), resulting in an error message.
146.It Fl R
147Same as
148.Fl r
149option.
150.El
151.Ss "/usr/bin/rm"
152The following options are supported for
153.Nm /usr/bin/rm
154only:
155.Bl -hang
156.It Fl f
157Removes all files (whether write-protected or not) in a directory without
158prompting the user.
159In a write-protected directory, however, files are never removed (whatever
160their permissions are), but no messages are displayed.
161If the removal of a write-protected directory is attempted, this option does
162not suppress an error message.
163.It Fl i
164Interactive.
165With this option,
166.Nm rm
167prompts for confirmation before
168removing any files.
169It overrides the
170.Fl f
171option and remains in effect even if the standard input is not a terminal.
172.El
173.Ss "/usr/xpg4/bin/rm"
174The following options are supported for
175.Nm /usr/xpg4/bin/rm
176only:
177.Bl -hang
178.It Fl f
179Does not prompt for confirmation.
180Does not write diagnostic messages or modify the exit status in the case of
181non-existent operands.
182Any previous occurrences of the
183.Fl i
184option is ignored.
185.It Fl i
186Prompts for confirmation.
187Any occurrences of the
188.Fl f
189option is ignored.
190.El
191.Ss "/usr/bin/rmdir"
192The following options are supported for
193.Nm /usr/bin/rmdir
194only:
195.Bl -hang
196.It Fl p
197Allows users to remove the directory
198.Ar dirname
199and its parent directories which become empty.
200A message is printed to standard error if all or part of the path could not be
201removed.
202.It Fl s
203Suppresses the message printed on the standard error when
204.Fl p
205is in effect.
206.El
207.Ss "ksh93"
208The following options are supported for the
209.Nm rmdir
210built-in for
211.Nm ksh93 :
212.Pp
213.Bl -hang -compact
214.It Fl e
215.It Fl -ignore-fail-on-non-empty
216Ignore each non-empty directory failure.
217.El
218.Pp
219.Bl -hang -compact
220.It Fl p
221.It Fl -parents
222Remove each explicit directory argument directory that becomes empty after its
223child directories are removed.
224.El
225.Pp
226.Bl -hang -compact
227.It Fl s
228.It Fl -suppress
229Suppress the message printed on the standard error when
230.Fl p
231is in effect.
232.El
233.Sh OPERANDS
234The following operands are supported:
235.Bl -tag -width Ar
236.It Ar file
237Specifies the pathname of a directory entry to be removed.
238.It Ar dirname
239Specifies the pathname of an empty directory to be removed.
240.El
241.Sh USAGE
242See
243.Xr largefile 5
244for the description of the behavior of
245.Nm rm
246and
247.Nm rmdir
248when encountering files greater than or equal to 2 Gbyte (2^31 bytes).
249.Sh EXIT STATUS
250The following exit values are returned:
251.Bl -tag -width Sy
252.It Sy 0
253If the
254.Fl f
255option was not specified, all the named directory entries were
256removed; otherwise, all the existing named directory entries were removed.
257.It Sy >0
258An error occurred.
259.El
260.Ss "ksh93"
261The following exit values are returned:
262.Bl -tag -width Sy
263.It Sy 0
264Successful completion.
265All directories deleted successfully.
266.It Sy  >0
267An error occurred.
268One or more directories could not be deleted.
269.El
270.Sh EXAMPLES
271The following examples are valid for the commands shown.
272.Ss "/usr/bin/rm, /usr/xpg4/bin/rm"
273.Bl -ohang
274.It Sy Example 1 No Removing Directories
275.Pp
276The following command removes the directory entries
277.Pa a.out
278and
279.Pa core :
280.Pp
281.Dl example% rm a.out core
282.El
283.Bl -ohang
284.It Sy Example 2 No Removing a Directory without Prompting
285.Pp
286The following command removes the directory
287.Pa junk
288and all its contents, without prompting:
289.Pp
290.Dl example% rm -rf junk
291.El
292.Ss "/usr/bin/rmdir"
293.Bl -ohang
294.It Sy Example 3 No Removing Empty Directories
295.Pp
296If a directory
297.Pa a
298in the current directory is empty, except that it contains a directory
299.Pa b ,
300and
301.Pa a/b
302is empty except that it contains a directory
303.Pa c ,
304the following command removes all three directories:
305.Pp
306.Dl example% rmdir -p a/b/c
307.El
308.Sh DIAGNOSTICS
309All messages are generally self-explanatory.
310.Pp
311It is forbidden to remove the files
312.Qq Pa \&.
313and
314.Qq Pa ..
315in order to
316avoid the consequences of inadvertently doing something like the following:
317.Pp
318.Dl example% rm -r .*
319.Pp
320It is forbidden to remove the file
321.Qq Pa /
322in order to avoid the consequences of inadvertently doing something like:
323.Pp
324.Dl example% rm -rf $x/$y
325.Pp
326or
327.Pp
328.Dl example% rm -rf /$y
329.Pp
330when
331.Va $x
332and
333.Va $y
334expand to empty strings.
335.Sh ENVIRONMENT VARIABLES
336See
337.Xr environ 5
338for descriptions of the following environment variables that affect the
339execution of
340.Nm rm
341and
342.Nm rmdir :
343.Ev LANG ,
344.Ev LC_ALL ,
345.Ev LC_COLLATE ,
346.Ev LC_CTYPE ,
347.Ev LC_MESSAGES ,
348and
349.Ev NLSPATH .
350.Pp
351Affirmative responses are processed using the extended regular expression
352defined for the
353.Sy yesexpr
354keyword in the
355.Ev LC_MESSAGES
356category of the
357user's locale.
358The locale specified in the
359.Ev LC_COLLATE
360category defines
361the behavior of ranges, equivalence classes, and multi-character collating
362elements used in the expression defined for
363.Sy yesexpr .
364The locale specified in
365.Ev LC_CTYPE
366determines the locale for interpretation of sequences of
367bytes of text data a characters, the behavior of character classes used in the
368expression defined for the
369.Sy yesexpr .
370See
371.Xr locale 5 .
372.Sh INTERFACE STABILITY
373.Ss "/usr/xpg4/bin/rm"
374Committed
375.Ss "ksh93"
376The
377.Nm ksh93
378built-in binding to
379.Pa /bin
380and
381.Pa /usr/bin
382is Volatile.
383The built-in interfaces are Uncommitted.
384.Sh SEE ALSO
385.Xr ksh93 1 ,
386.Xr rmdir 2 ,
387.Xr rmdir 2 ,
388.Xr unlink 2 ,
389.Xr attributes 5 ,
390.Xr environ 5 ,
391.Xr largefile 5 ,
392.Xr standards 5
393.Sh NOTES
394A
395.Fl
396permits the user to mark explicitly the end of any command line options,
397allowing
398.Nm rm
399to recognize file arguments that begin with a
400.Fl .
401As an aid to BSD migration,
402.Nm rm
403accepts
404.Fl -
405as a synonym for
406.Fl .
407This migration aid may disappear in a future release.
408If a
409.Fl -
410and a
411.Fl
412both appear on the same command line, the second is interpreted as a file.
413