xref: /freebsd/bin/rm/rm.1 (revision c8e7f78a3d28ff6e6223ed136ada8e1e2f34965e)
1.\"-
2.\" Copyright (c) 1990, 1993, 1994
3.\"	The Regents of the University of California.  All rights reserved.
4.\"
5.\" This code is derived from software contributed to Berkeley by
6.\" the Institute of Electrical and Electronics Engineers, Inc.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.Dd November 10, 2018
33.Dt RM 1
34.Os
35.Sh NAME
36.Nm rm ,
37.Nm unlink
38.Nd remove directory entries
39.Sh SYNOPSIS
40.Nm
41.Op Fl f | i
42.Op Fl dIRrvWx
43.Ar
44.Nm unlink
45.Op Fl -
46.Ar file
47.Sh DESCRIPTION
48The
49.Nm
50utility attempts to remove the non-directory type files specified on the
51command line.
52If the permissions of the file do not permit writing, and the standard
53input device is a terminal, the user is prompted (on the standard error
54output) for confirmation.
55.Pp
56The options are as follows:
57.Bl -tag -width indent
58.It Fl d
59Attempt to remove directories as well as other types of files.
60.It Fl f
61Attempt to remove the files without prompting for confirmation,
62regardless of the file's permissions.
63If the file does not exist, do not display a diagnostic message or modify
64the exit status to reflect an error.
65The
66.Fl f
67option overrides any previous
68.Fl i
69options.
70.It Fl i
71Request confirmation before attempting to remove each file, regardless of
72the file's permissions, or whether or not the standard input device is a
73terminal.
74The
75.Fl i
76option overrides any previous
77.Fl f
78options.
79.It Fl I
80Request confirmation once if more than three files are being removed or if a
81directory is being recursively removed.
82This is a far less intrusive option than
83.Fl i
84yet provides almost the same level of protection against mistakes.
85.It Fl P
86This flag has no effect.
87It is kept only for backwards compatibility with
88.Bx 4.4 Lite2 .
89.It Fl R
90Attempt to remove the file hierarchy rooted in each
91.Ar file
92argument.
93The
94.Fl R
95option implies the
96.Fl d
97option.
98If the
99.Fl i
100option is specified, the user is prompted for confirmation before
101each directory's contents are processed (as well as before the attempt
102is made to remove the directory).
103If the user does not respond affirmatively, the file hierarchy rooted in
104that directory is skipped.
105.It Fl r
106Equivalent to
107.Fl R .
108.It Fl v
109Be verbose when deleting files, showing them as they are removed.
110.It Fl W
111Attempt to undelete the named files.
112Currently, this option can only be used to recover
113files covered by whiteouts in a union file system (see
114.Xr undelete 2 ) .
115.It Fl x
116When removing a hierarchy, do not cross mount points.
117.El
118.Pp
119The
120.Nm
121utility removes symbolic links, not the files referenced by the links.
122.Pp
123It is an error to attempt to remove the files
124.Pa / ,
125.Pa .\&
126or
127.Pa .. .
128.Pp
129When the utility is called as
130.Nm unlink ,
131only one argument,
132which must not be a directory,
133may be supplied.
134No options may be supplied in this simple mode of operation,
135which performs an
136.Xr unlink 2
137operation on the passed argument.
138However, the usual option-end delimiter,
139.Fl - ,
140may optionally precede the argument.
141.Sh EXIT STATUS
142The
143.Nm
144utility exits 0 if all of the named files or file hierarchies were removed,
145or if the
146.Fl f
147option was specified and all of the existing files or file hierarchies were
148removed.
149If an error occurs,
150.Nm
151exits with a value >0.
152.Sh NOTES
153The
154.Nm
155command uses
156.Xr getopt 3
157to parse its arguments, which allows it to accept
158the
159.Sq Li --
160option which will cause it to stop processing flag options at that
161point.
162This will allow the removal of file names that begin
163with a dash
164.Pq Sq - .
165For example:
166.Pp
167.Dl "rm -- -filename"
168.Pp
169The same behavior can be obtained by using an absolute or relative
170path reference.
171For example:
172.Pp
173.Dl "rm /home/user/-filename"
174.Dl "rm ./-filename"
175.Sh EXAMPLES
176Recursively remove all files contained within the
177.Pa foobar
178directory hierarchy:
179.Pp
180.Dl $ rm -rf foobar
181.Pp
182Any of these commands will remove the file
183.Pa -f :
184.Bd -literal -offset indent
185$ rm -- -f
186$ rm ./-f
187$ unlink -f
188.Ed
189.Sh COMPATIBILITY
190The
191.Nm
192utility differs from historical implementations in that the
193.Fl f
194option only masks attempts to remove non-existent files instead of
195masking a large variety of errors.
196The
197.Fl v
198option is non-standard and its use in scripts is not recommended.
199.Pp
200Also, historical
201.Bx
202implementations prompted on the standard output,
203not the standard error output.
204.Pp
205The
206.Fl P
207option does not have any effect as of
208.Fx 13
209and may be removed in the future.
210.Sh SEE ALSO
211.Xr chflags 1 ,
212.Xr rmdir 1 ,
213.Xr undelete 2 ,
214.Xr unlink 2 ,
215.Xr fts 3 ,
216.Xr getopt 3 ,
217.Xr symlink 7
218.Sh STANDARDS
219The
220.Nm
221command conforms to
222.St -p1003.1-2013 .
223.Pp
224The simplified
225.Nm unlink
226command conforms to
227.St -susv2 .
228.Sh HISTORY
229A
230.Nm
231command appeared in
232.At v1 .
233