xref: /openbsd-src/bin/rm/rm.1 (revision 647427d6f39b02be77397484b468d703ecda3237)
1.\"	$OpenBSD: rm.1,v 1.44 2019/09/02 21:18:41 deraadt Exp $
2.\"	$NetBSD: rm.1,v 1.8 1995/07/25 19:37:30 jtc Exp $
3.\"
4.\" Copyright (c) 1990, 1993, 1994
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" This code is derived from software contributed to Berkeley by
8.\" the Institute of Electrical and Electronics Engineers, Inc.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"	@(#)rm.1	8.5 (Berkeley) 12/5/94
35.\"
36.Dd $Mdocdate: September 2 2019 $
37.Dt RM 1
38.Os
39.Sh NAME
40.Nm rm
41.Nd remove directory entries
42.Sh SYNOPSIS
43.Nm rm
44.Op Fl dfiPRrv
45.Ar
46.Sh DESCRIPTION
47The
48.Nm
49utility attempts to remove the non-directory type files specified on the
50command line.
51If the permissions of the file do not permit writing, and the standard
52input device is a terminal, the user is prompted (on the standard error
53output) for confirmation.
54.Pp
55The options are as follows:
56.Bl -tag -width Ds
57.It Fl d
58Attempt to remove directories as well as other types of files.
59.It Fl f
60Attempt to remove the files without prompting for confirmation,
61regardless of the file's permissions.
62If the file does not exist, do not display a diagnostic message or modify
63the exit status to reflect an error.
64The
65.Fl f
66option overrides any previous
67.Fl i
68options.
69.It Fl i
70Request confirmation before attempting to remove each file, regardless of
71the file's permissions, or whether or not the standard input device is a
72terminal.
73The
74.Fl i
75option overrides any previous
76.Fl f
77options.
78.It Fl P
79Attempt to overwrite regular writable files before deleting them.
80Files are overwritten once with a random pattern.
81Files with multiple links will be unlinked but not overwritten.
82.It Fl R
83Attempt to remove the file hierarchy rooted in each file argument.
84The
85.Fl R
86option implies the
87.Fl d
88option.
89If the
90.Fl i
91option is specified, the user is prompted for confirmation before
92each directory (and its contents) are processed.
93If the user does not respond affirmatively, the file hierarchy rooted in
94that directory is skipped.
95.It Fl r
96Equivalent to
97.Fl R .
98.It Fl v
99Display each file name after it was removed.
100.El
101.Pp
102The
103.Nm
104utility removes symbolic links, not the files referenced by the links.
105.Pp
106It is an error to attempt to remove the root directory or the files
107.Dq \&.
108or
109.Dq .. .
110It is forbidden to remove the file
111.Dq ..
112merely to avoid the antisocial consequences of inadvertently
113doing something like
114.Dq Cm rm -r .* .
115.Sh EXIT STATUS
116The
117.Nm
118utility exits 0 if all of the named files or file hierarchies were removed,
119or if the
120.Fl f
121option was specified and all of the existing files or file hierarchies were
122removed.
123If an error occurs,
124.Nm
125exits with a value >0.
126.Sh EXAMPLES
127Recursively remove all files contained within the
128.Pa foobar
129directory hierarchy:
130.Pp
131.Dl $ rm -rf foobar
132.Pp
133Either of these commands will remove the file
134.Pa -f :
135.Bd -literal -offset indent
136$ rm -- -f
137$ rm ./-f
138.Ed
139.Sh SEE ALSO
140.Xr rmdir 1 ,
141.\" .Xr undelete 2 ,
142.Xr unlink 2 ,
143.Xr fts_open 3 ,
144.Xr symlink 7
145.Sh STANDARDS
146The
147.Nm
148utility is compliant with the
149.St -p1003.1-2008
150specification.
151.Pp
152The flags
153.Op Fl dPv
154are extensions to that specification.
155.Sh HISTORY
156An
157.Nm
158command appeared in
159.At v1 .
160.Pp
161The
162.Nm
163utility differs from historical implementations in that the
164.Fl f
165option only masks attempts to remove non-existent files instead of
166masking a large variety of errors.
167.Pp
168Also, historical
169.Bx
170implementations prompted on the standard output,
171not the standard error output.
172.Pp
173The interactive mode used to be a
174.Nm dsw
175command, a carryover from the ancient past with an
176amusing etymology.
177.Sh BUGS
178The
179.Fl P
180option assumes that both the underlying file system and storage medium write
181in place.
182This is true for the FFS and MS-DOS file systems and magnetic hard disks,
183but not true for most flash storage.
184In addition, only regular files are overwritten; other types of files
185are not.
186