xref: /freebsd/bin/rm/rm.1 (revision bd15659f64eb4460b85f395a176de9d4fcf40ecb)
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.\" 4. 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 October 28, 2004
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 dfiIPRrvW
45.Ar
46.Nm unlink
47.Ar file
48.Sh DESCRIPTION
49The
50.Nm
51utility attempts to remove the non-directory type files specified on the
52command line.
53If the permissions of the file do not permit writing, and the standard
54input device is a terminal, the user is prompted (on the standard error
55output) for confirmation.
56.Pp
57The options are as follows:
58.Bl -tag -width Fl
59.It Fl d
60Attempt to remove directories as well as other types of files.
61.It Fl f
62Attempt to remove the files without prompting for confirmation,
63regardless of the file's permissions.
64If the file does not exist, do not display a diagnostic message or modify
65the exit status to reflect an error.
66The
67.Fl f
68option overrides any previous
69.Fl i
70options.
71.It Fl i
72Request confirmation before attempting to remove each file, regardless of
73the file's permissions, or whether or not the standard input device is a
74terminal.
75The
76.Fl i
77option overrides any previous
78.Fl f
79options.
80.It Fl I
81Request confirmation once if more than three files are being removed or if a
82directory is being recursively removed.
83This is a far less intrusive option than
84.Fl i
85yet provides almost the same level of protection against mistakes.
86.It Fl P
87Overwrite regular files before deleting them.
88Files are overwritten three times, first with the byte pattern 0xff,
89then 0x00, and then 0xff again, before they are deleted.
90.It Fl R
91Attempt to remove the file hierarchy rooted in each file argument.
92The
93.Fl R
94option implies the
95.Fl d
96option.
97If the
98.Fl i
99option is specified, the user is prompted for confirmation before
100each directory's contents are processed (as well as before the attempt
101is made to remove the directory).
102If the user does not respond affirmatively, the file hierarchy rooted in
103that directory is skipped.
104.Pp
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.
114.El
115.Pp
116The
117.Nm
118utility removes symbolic links, not the files referenced by the links.
119.Pp
120It is an error to attempt to remove the files
121.Pa / ,
122.Pa .\&
123or
124.Pa .. .
125.Pp
126When the utility is called as
127.Nm unlink ,
128only one argument,
129which must not be a directory,
130may be supplied.
131No options may be supplied in this simple mode of operation,
132which performs an
133.Xr unlink 2
134operation on the passed argument.
135.Pp
136The
137.Nm
138utility exits 0 if all of the named files or file hierarchies were removed,
139or if the
140.Fl f
141option was specified and all of the existing files or file hierarchies were
142removed.
143If an error occurs,
144.Nm
145exits with a value >0.
146.Sh NOTE
147The
148.Nm
149command uses
150.Xr getopt 3
151to parse its arguments, which allows it to accept
152the
153.Sq Li --
154option which will cause it to stop processing flag options at that
155point.
156This will allow the removal of file names that begin
157with a dash
158.Pq Sq - .
159For example:
160.Dl rm -- -filename
161The same behavior can be obtained by using an absolute or relative
162path reference.
163For example:
164.Dl rm /home/user/-filename
165.Dl rm ./-filename
166.Sh SEE ALSO
167.Xr chflags 1 ,
168.Xr rmdir 1 ,
169.Xr undelete 2 ,
170.Xr unlink 2 ,
171.Xr fts 3 ,
172.Xr getopt 3 ,
173.Xr symlink 7
174.Sh BUGS
175The
176.Fl P
177option assumes that the underlying file system is a fixed-block file
178system.
179UFS is a fixed-block file system, LFS is not.
180In addition, only regular files are overwritten, other types of files
181are not.
182.Sh COMPATIBILITY
183The
184.Nm
185utility differs from historical implementations in that the
186.Fl f
187option only masks attempts to remove non-existent files instead of
188masking a large variety of errors.
189The
190.Fl v
191option is non-standard and its use in scripts is not recommended.
192.Pp
193Also, historical
194.Bx
195implementations prompted on the standard output,
196not the standard error output.
197.Sh STANDARDS
198The
199.Nm
200command conforms to
201.St -p1003.2 .
202.Pp
203The simplified
204.Nm unlink
205command conforms to
206.St -susv2 .
207.Sh HISTORY
208A
209.Nm
210command appeared in
211.At v1 .
212