xref: /freebsd/bin/rm/rm.1 (revision 2a01feab)
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.\"	@(#)rm.1	8.5 (Berkeley) 12/5/94
33.\" $FreeBSD$
34.\"
35.Dd September 12, 2018
36.Dt RM 1
37.Os
38.Sh NAME
39.Nm rm ,
40.Nm unlink
41.Nd remove directory entries
42.Sh SYNOPSIS
43.Nm
44.Op Fl f | i
45.Op Fl dIPRrvWx
46.Ar
47.Nm unlink
48.Op Fl -
49.Ar file
50.Sh DESCRIPTION
51The
52.Nm
53utility attempts to remove the non-directory type files specified on the
54command line.
55If the permissions of the file do not permit writing, and the standard
56input device is a terminal, the user is prompted (on the standard error
57output) for confirmation.
58.Pp
59The options are as follows:
60.Bl -tag -width indent
61.It Fl d
62Attempt to remove directories as well as other types of files.
63.It Fl f
64Attempt to remove the files without prompting for confirmation,
65regardless of the file's permissions.
66If the file does not exist, do not display a diagnostic message or modify
67the exit status to reflect an error.
68The
69.Fl f
70option overrides any previous
71.Fl i
72options.
73.It Fl i
74Request confirmation before attempting to remove each file, regardless of
75the file's permissions, or whether or not the standard input device is a
76terminal.
77The
78.Fl i
79option overrides any previous
80.Fl f
81options.
82.It Fl I
83Request confirmation once if more than three files are being removed or if a
84directory is being recursively removed.
85This is a far less intrusive option than
86.Fl i
87yet provides almost the same level of protection against mistakes.
88.It Fl P
89Overwrite regular files before deleting them.
90Files are overwritten three times, first with the byte pattern 0xff,
91then 0x00, and then 0xff again, before they are deleted.
92Files with multiple links will not be overwritten nor deleted
93and a warning will be issued.
94If the
95.Fl f
96option is specified, files with multiple links will also be overwritten
97and deleted.
98No warning will be issued.
99.Pp
100Specifying this flag for a read only file will cause
101.Nm
102to generate an error message and exit.
103The file will not be removed or overwritten.
104.Pp
105N.B.: The
106.Fl P
107flag is not considered a security feature
108.Pq see Sx BUGS .
109.It Fl R
110Attempt to remove the file hierarchy rooted in each
111.Ar file
112argument.
113The
114.Fl R
115option implies the
116.Fl d
117option.
118If the
119.Fl i
120option is specified, the user is prompted for confirmation before
121each directory's contents are processed (as well as before the attempt
122is made to remove the directory).
123If the user does not respond affirmatively, the file hierarchy rooted in
124that directory is skipped.
125.It Fl r
126Equivalent to
127.Fl R .
128.It Fl v
129Be verbose when deleting files, showing them as they are removed.
130.It Fl W
131Attempt to undelete the named files.
132Currently, this option can only be used to recover
133files covered by whiteouts in a union file system (see
134.Xr undelete 2 ) .
135.It Fl x
136When removing a hierarchy, do not cross mount points.
137.El
138.Pp
139The
140.Nm
141utility removes symbolic links, not the files referenced by the links.
142.Pp
143It is an error to attempt to remove the files
144.Pa / ,
145.Pa .\&
146or
147.Pa .. .
148.Pp
149When the utility is called as
150.Nm unlink ,
151only one argument,
152which must not be a directory,
153may be supplied.
154No options may be supplied in this simple mode of operation,
155which performs an
156.Xr unlink 2
157operation on the passed argument.
158However, the usual option-end delimiter,
159.Fl - ,
160may optionally precede the argument.
161.Sh EXIT STATUS
162The
163.Nm
164utility exits 0 if all of the named files or file hierarchies were removed,
165or if the
166.Fl f
167option was specified and all of the existing files or file hierarchies were
168removed.
169If an error occurs,
170.Nm
171exits with a value >0.
172.Sh NOTES
173The
174.Nm
175command uses
176.Xr getopt 3
177to parse its arguments, which allows it to accept
178the
179.Sq Li --
180option which will cause it to stop processing flag options at that
181point.
182This will allow the removal of file names that begin
183with a dash
184.Pq Sq - .
185For example:
186.Pp
187.Dl "rm -- -filename"
188.Pp
189The same behavior can be obtained by using an absolute or relative
190path reference.
191For example:
192.Pp
193.Dl "rm /home/user/-filename"
194.Dl "rm ./-filename"
195.Pp
196When
197.Fl P
198is specified with
199.Fl f
200the file will be overwritten and removed even if it has hard links.
201.Sh EXAMPLES
202Recursively remove all files contained within the
203.Pa foobar
204directory hierarchy:
205.Pp
206.Dl $ rm -rf foobar
207.Pp
208Any of these commands will remove the file
209.Pa -f :
210.Bd -literal -offset indent
211$ rm -- -f
212$ rm ./-f
213$ unlink -f
214.Ed
215.Sh COMPATIBILITY
216The
217.Nm
218utility differs from historical implementations in that the
219.Fl f
220option only masks attempts to remove non-existent files instead of
221masking a large variety of errors.
222The
223.Fl v
224option is non-standard and its use in scripts is not recommended.
225.Pp
226Also, historical
227.Bx
228implementations prompted on the standard output,
229not the standard error output.
230.Sh SEE ALSO
231.Xr chflags 1 ,
232.Xr rmdir 1 ,
233.Xr undelete 2 ,
234.Xr unlink 2 ,
235.Xr fts 3 ,
236.Xr getopt 3 ,
237.Xr symlink 7
238.Sh STANDARDS
239The
240.Nm
241command conforms to
242.St -p1003.1-2013 .
243.Pp
244The simplified
245.Nm unlink
246command conforms to
247.St -susv2 .
248.Sh HISTORY
249A
250.Nm
251command appeared in
252.At v1 .
253.Sh BUGS
254The
255.Fl P
256option assumes that the underlying storage overwrites file blocks
257when data is written to an existing offset.
258Several factors including the file system and its backing store could defeat
259this assumption.
260This includes, but is not limited to file systems that use a
261Copy-On-Write strategy (e.g. ZFS or UFS when snapshots are being used), Flash
262media that are using a wear leveling algorithm, or when the backing datastore
263does journaling, etc.
264In addition, only regular files are overwritten, other types of files are not.
265