1.\"	$MirOS: src/bin/rm/rm.1,v 1.4 2009/01/17 11:27:05 tg Exp $
2.\"	$NetBSD: rm.1,v 1.24 2006/09/02 23:28:32 wiz Exp $
3.\"	$OpenBSD: rm.1,v 1.25 2005/06/14 19:15:35 millert Exp $
4.\"
5.\" Copyright (c) 1990, 1993, 1994, 2003
6.\"	The Regents of the University of California.  All rights reserved.
7.\"
8.\" This code is derived from software contributed to Berkeley by
9.\" the Institute of Electrical and Electronics Engineers, Inc.
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\" 1. Redistributions of source code must retain the above copyright
15.\"    notice, this list of conditions and the following disclaimer.
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\"    notice, this list of conditions and the following disclaimer in the
18.\"    documentation and/or other materials provided with the distribution.
19.\" 3. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\"	@(#)rm.1	8.5 (Berkeley) 12/5/94
36.\"
37.Dd $Mdocdate: January 17 2009 $
38.Dt RM 1
39.Os
40.Sh NAME
41.Nm rm
42.Nd remove directory entries
43.Sh SYNOPSIS
44.Nm
45.Op Fl f | Fl i
46.Op Fl dPRrv
47.Ar
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 Ds
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 P
81Overwrite regular files before deleting them.
82Files are overwritten three times, first with the byte pattern
83.Li 0xAA ,
84then
85.Li 0x55 ,
86and then with random data, before they are deleted.
87Some care is taken to ensure that the data are actually written to
88disk, but this cannot be guaranteed, even on traditional filesystems;
89on log-structured filesystems or if any block-journaling scheme is
90in use, this option is completely useless.
91If the file cannot be
92overwritten, it will not be removed.
93.Pp
94Files with multiple links will not be overwritten.
95If the
96.Fl f
97option is given, they will still be removed,
98otherwise, they will remain untouched.
99.Pp
100Entries are renamed to the basename
101.Dq Li rm.XXXXXXXX
102.Pq where So X Sc are generated randomly
103within the same parent directory before removing,
104if the length of the generated total pathname will not overflow the buffer.
105This prevents recovery of (almost) all basenames as well.
106.It Fl R
107Attempt to remove the file hierarchy rooted in each file argument.
108The
109.Fl R
110option implies the
111.Fl d
112option.
113If the
114.Fl i
115option is specified, the user is prompted for confirmation before
116each directory's contents are processed (as well as before the attempt
117is made to remove the directory).
118If the user does not respond affirmatively, the file hierarchy rooted in
119that directory is skipped.
120.Pp
121.It Fl r
122Equivalent to
123.Fl R .
124.It Fl v
125Cause
126.Nm
127to be verbose, showing files as they are processed.
128.El
129.Pp
130The
131.Nm
132utility removes symbolic links, not the files referenced by the links.
133.Pp
134It is an error to attempt to remove the files
135.Dq \&.
136or
137.Dq .. .
138It is forbidden to remove the file
139.Dq ..
140merely to avoid the antisocial consequences of inadvertently
141doing something like
142.Dq Cm rm -r .* .
143.Pp
144The
145.Nm
146utility exits 0 if all of the named files or file hierarchies were removed,
147or if the
148.Fl f
149option was specified and all of the existing files or file hierarchies were
150removed.
151If an error occurs,
152.Nm
153exits with a value \*(Gt0.
154.Sh EXAMPLES
155Recursively remove all files contained within the
156.Pa foobar
157directory hierarchy:
158.Pp
159.Dl $ rm -rf foobar
160.Pp
161.Nm
162uses
163.Xr getopt 3
164standard argument processing.
165Removing filenames that begin with a dash
166.Pq e.g., Ar -file
167in the current directory which might otherwise be taken as option flags to
168.Nm
169can be accomplished as follows:
170.Pp
171.Ic "rm -- -file"
172.Pp
173or
174.Pp
175.Ic "rm ./-file"
176.Sh SEE ALSO
177.Xr rmdir 1 ,
178.\".Xr undelete 2 ,
179.Xr unlink 2 ,
180.Xr arc4random 3 ,
181.Xr fts 3 ,
182.Xr getopt 3 ,
183.Xr symlink 7
184.Sh STANDARDS
185The
186.Nm
187utility differs from historical implementations in that the
188.Fl f
189option only masks attempts to remove non-existent files instead of
190masking a large variety of errors.
191.Pp
192Also, historical
193.Bx
194implementations prompted on the standard output,
195not the standard error output.
196.Pp
197The interactive mode used to be a
198.Nm dsw
199command, a carryover from the ancient past with an
200amusing etymology.
201.Pp
202The
203.Nm
204utility is almost
205.St -p1003.2
206compatible, except that
207.Tn POSIX
208requires
209.Nm
210to act like
211.Xr rmdir 1
212when the
213.Ar file
214specified is a directory.
215This implementation requires the
216.Fl d
217option if such behavior is desired.
218This follows the historical
219behavior of
220.Nm
221with respect to directories.
222.Pp
223The
224.Fl v
225option is an extension.
226.Pp
227The
228.Fl P
229option attempts to conform to U.S. DoD 5220-22.M, "National Industrial
230Security Program Operating Manual" ("NISPOM") as updated by Change
2312 and the July 23, 2003 "Clearing & Sanitization Matrix".
232However, unlike earlier revisions of NISPOM, the 2003 matrix imposes
233requirements which make it clear that the standard does not and
234can not apply to the erasure of individual files, in particular
235requirements relating to spare sector management for an entire
236magnetic disk.
237.Em Because these requirements are not met, the
238.Fl P
239.Em option does not conform to the standard .
240.Sh HISTORY
241An
242.Nm
243command appeared in
244.At v1 .
245.Pp
246Modification of the
247.Fl P
248option to overwrite with random content and rename entries
249to random filenames before removal appeared in
250.Mx 10 .
251.Sh BUGS
252The
253.Fl P
254option assumes that the underlying file system is a fixed-block file
255system.
256FFS is a fixed-block file system, LFS is not.
257In addition, only regular files are overwritten, other types of files
258are not.
259Recent research indicates that as many as 35 overwrite passes with
260carefully chosen data patterns may be necessary to actually prevent
261recovery of data from a magnetic disk.
262Thus the
263.Fl P
264option is likely both insufficient for its design purpose and far
265too costly for default operation.
266However, it will at least prevent the recovery of data from FFS
267volumes with
268.Xr fsdb 8 .
269