xref: /netbsd-src/bin/rm/rm.1 (revision 01869ca4d24a86379a68731bf9706a9f0820fe4e)
1*01869ca4Swiz.\"	$NetBSD: rm.1,v 1.29 2017/07/03 21:33:23 wiz Exp $
249f0ad86Scgd.\"
3c271c159Sjrf.\" Copyright (c) 1990, 1993, 1994, 2003
49baa91f3Smycroft.\"	The Regents of the University of California.  All rights reserved.
561f28255Scgd.\"
661f28255Scgd.\" This code is derived from software contributed to Berkeley by
761f28255Scgd.\" the Institute of Electrical and Electronics Engineers, Inc.
861f28255Scgd.\"
961f28255Scgd.\" Redistribution and use in source and binary forms, with or without
1061f28255Scgd.\" modification, are permitted provided that the following conditions
1161f28255Scgd.\" are met:
1261f28255Scgd.\" 1. Redistributions of source code must retain the above copyright
1361f28255Scgd.\"    notice, this list of conditions and the following disclaimer.
1461f28255Scgd.\" 2. Redistributions in binary form must reproduce the above copyright
1561f28255Scgd.\"    notice, this list of conditions and the following disclaimer in the
1661f28255Scgd.\"    documentation and/or other materials provided with the distribution.
17b5b29542Sagc.\" 3. Neither the name of the University nor the names of its contributors
1861f28255Scgd.\"    may be used to endorse or promote products derived from this software
1961f28255Scgd.\"    without specific prior written permission.
2061f28255Scgd.\"
2161f28255Scgd.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2261f28255Scgd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2361f28255Scgd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2461f28255Scgd.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2561f28255Scgd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2661f28255Scgd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2761f28255Scgd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2861f28255Scgd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2961f28255Scgd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3061f28255Scgd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3161f28255Scgd.\" SUCH DAMAGE.
3261f28255Scgd.\"
3349f0ad86Scgd.\"	@(#)rm.1	8.5 (Berkeley) 12/5/94
34346aa5ddScgd.\"
3515dc5a00Ssevan.Dd August 12, 2016
3661f28255Scgd.Dt RM 1
3761f28255Scgd.Os
3861f28255Scgd.Sh NAME
3961f28255Scgd.Nm rm
409baa91f3Smycroft.Nd remove directory entries
4161f28255Scgd.Sh SYNOPSIS
42c3872193Senami.Nm
4361f28255Scgd.Op Fl f | Fl i
44aab67d52Schristos.Op Fl dPRrvWx
459ca32dd3Senami.Ar
4661f28255Scgd.Sh DESCRIPTION
4761f28255ScgdThe
48c3872193Senami.Nm
4961f28255Scgdutility attempts to remove the non-directory type files specified on the
5061f28255Scgdcommand line.
5161f28255ScgdIf the permissions of the file do not permit writing, and the standard
5261f28255Scgdinput device is a terminal, the user is prompted (on the standard error
5361f28255Scgdoutput) for confirmation.
5461f28255Scgd.Pp
5561f28255ScgdThe options are as follows:
5661f28255Scgd.Bl -tag -width flag
5761f28255Scgd.It Fl d
5861f28255ScgdAttempt to remove directories as well as other types of files.
5961f28255Scgd.It Fl f
6061f28255ScgdAttempt to remove the files without prompting for confirmation,
6161f28255Scgdregardless of the file's permissions.
6261f28255ScgdIf the file does not exist, do not display a diagnostic message or modify
6361f28255Scgdthe exit status to reflect an error.
6461f28255ScgdThe
6561f28255Scgd.Fl f
6661f28255Scgdoption overrides any previous
6761f28255Scgd.Fl i
6861f28255Scgdoptions.
6961f28255Scgd.It Fl i
7061f28255ScgdRequest confirmation before attempting to remove each file, regardless of
7161f28255Scgdthe file's permissions, or whether or not the standard input device is a
7261f28255Scgdterminal.
7361f28255ScgdThe
7461f28255Scgd.Fl i
7561f28255Scgdoption overrides any previous
7661f28255Scgd.Fl f
7761f28255Scgdoptions.
789baa91f3Smycroft.It Fl P
799baa91f3SmycroftOverwrite regular files before deleting them.
809baa91f3SmycroftFiles are overwritten three times, first with the byte pattern 0xff,
811763875aSwizthen 0x00, and then with random data, before they are deleted.
821763875aSwizSome care is taken to ensure that the data are actually written to
831763875aSwizdisk, but this cannot be guaranteed, even on traditional filesystems;
841763875aSwizon log-structured filesystems or if any block-journaling scheme is
851763875aSwizin use, this option is completely useless.
861763875aSwizIf the file cannot be
8705907325Sliamjfoyoverwritten, it will not be removed.
8861f28255Scgd.It Fl R
8961f28255ScgdAttempt to remove the file hierarchy rooted in each file argument.
9061f28255ScgdThe
9161f28255Scgd.Fl R
9261f28255Scgdoption implies the
9361f28255Scgd.Fl d
9461f28255Scgdoption.
9561f28255ScgdIf the
9661f28255Scgd.Fl i
9761f28255Scgdoption is specified, the user is prompted for confirmation before
9861f28255Scgdeach directory's contents are processed (as well as before the attempt
9961f28255Scgdis made to remove the directory).
10061f28255ScgdIf the user does not respond affirmatively, the file hierarchy rooted in
10161f28255Scgdthat directory is skipped.
10261f28255Scgd.It Fl r
10361f28255ScgdEquivalent to
10461f28255Scgd.Fl R .
105c271c159Sjrf.It Fl v
106c271c159SjrfCause
107c271c159Sjrf.Nm
108c271c159Sjrfto be verbose, showing files as they are processed.
1090155aa3bSmycroft.It Fl W
1100155aa3bSmycroftAttempts to undelete the named files.
1110155aa3bSmycroftCurrently, this option can only be used to recover
1120155aa3bSmycroftfiles covered by whiteouts.
113aab67d52Schristos.It Fl x
114aab67d52SchristosWhen removing a hierarchy, do not cross mount points.
11561f28255Scgd.El
11661f28255Scgd.Pp
11761f28255ScgdThe
118c3872193Senami.Nm
11961f28255Scgdutility removes symbolic links, not the files referenced by the links.
12061f28255Scgd.Pp
12161f28255ScgdIt is an error to attempt to remove the files ``.'' and ``..''.
1222caf6aacSkleink.Sh EXIT STATUS
12361f28255ScgdThe
124c3872193Senami.Nm
12561f28255Scgdutility exits 0 if all of the named files or file hierarchies were removed,
12661f28255Scgdor if the
12761f28255Scgd.Fl f
12861f28255Scgdoption was specified and all of the existing files or file hierarchies were
12961f28255Scgdremoved.
13061f28255ScgdIf an error occurs,
131c3872193Senami.Nm
132*01869ca4Swizexits with a value >0.
1338cb13529Swiz.Sh EXAMPLES
1348cb13529Swiz.Nm
1358cb13529Swizuses
1368cb13529Swiz.Xr getopt 3
1378cb13529Swizstandard argument processing.
1388cb13529SwizRemoving filenames that begin with a dash
1398cb13529Swiz.Pq e.g., Ar -file
1408cb13529Swizin the current directory which might otherwise be taken as option flags to
1418cb13529Swiz.Nm
1428cb13529Swizcan be accomplished as follows:
1438cb13529Swiz.Pp
1448cb13529Swiz.Ic "rm -- -file"
1458cb13529Swiz.Pp
1468cb13529Swizor
1478cb13529Swiz.Pp
1488cb13529Swiz.Ic "rm ./-file"
14961f28255Scgd.Sh COMPATIBILITY
15061f28255ScgdThe
151c3872193Senami.Nm
15261f28255Scgdutility differs from historical implementations in that the
15361f28255Scgd.Fl f
15461f28255Scgdoption only masks attempts to remove non-existent files instead of
15561f28255Scgdmasking a large variety of errors.
15661f28255Scgd.Pp
15761f28255ScgdAlso, historical
15861f28255Scgd.Bx
15961f28255Scgdimplementations prompted on the standard output,
16061f28255Scgdnot the standard error output.
161eb5604b0Swiz.Sh SEE ALSO
162eb5604b0Swiz.Xr rmdir 1 ,
163eb5604b0Swiz.Xr undelete 2 ,
164eb5604b0Swiz.Xr unlink 2 ,
165eb5604b0Swiz.Xr fts 3 ,
166eb5604b0Swiz.Xr getopt 3 ,
167eb5604b0Swiz.Xr symlink 7
16861f28255Scgd.Sh STANDARDS
16961f28255ScgdThe
170c3872193Senami.Nm
17123e6aab1Sjtcutility is expected to be
17261f28255Scgd.St -p1003.2
17393f423f2Swizcompatible.
17493f423f2SwizThe
175c271c159Sjrf.Fl v
176aab67d52Schristosand
177aab67d52Schristos.Fl x
178aab67d52Schristosoptions are extensions.
179e9e0ca41Stls.Pp
180e9e0ca41StlsThe
181e9e0ca41Stls.Fl P
182a714cd57Swizoption attempts to conform to U.S. DoD 5220-22.M, "National Industrial
183a714cd57SwizSecurity Program Operating Manual" ("NISPOM") as updated by Change
184*01869ca4Swiz2 and the July 23, 2003 "Clearing & Sanitization Matrix".
185a714cd57SwizHowever, unlike earlier revisions of NISPOM, the 2003 matrix imposes
186a714cd57Swizrequirements which make it clear that the standard does not and
187a714cd57Swizcan not apply to the erasure of individual files, in particular
188a714cd57Swizrequirements relating to spare sector management for an entire
189a714cd57Swizmagnetic disk.
190e9e0ca41Stls.Em Because these requirements are not met, the
191e9e0ca41Stls.Fl P
192e9e0ca41Stls.Em option does not conform to the standard .
19315dc5a00Ssevan.Sh HISTORY
19415dc5a00SsevanAn
19515dc5a00Ssevan.Nm
19615dc5a00Ssevanutility appeared in
19715dc5a00Ssevan.At v1 .
198eb5604b0Swiz.Sh BUGS
199eb5604b0SwizThe
200eb5604b0Swiz.Fl P
201eb5604b0Swizoption assumes that the underlying file system is a fixed-block file
202eb5604b0Swizsystem.
203eb5604b0SwizFFS is a fixed-block file system, LFS is not.
204eb5604b0SwizIn addition, only regular files are overwritten, other types of files
205eb5604b0Swizare not.
206eb5604b0SwizRecent research indicates that as many as 35 overwrite passes with
207eb5604b0Swizcarefully chosen data patterns may be necessary to actually prevent
208eb5604b0Swizrecovery of data from a magnetic disk.
209eb5604b0SwizThus the
210eb5604b0Swiz.Fl P
211eb5604b0Swizoption is likely both insufficient for its design purpose and far
212eb5604b0Swiztoo costly for default operation.
213eb5604b0SwizHowever, it will at least prevent the recovery of data from FFS
214eb5604b0Swizvolumes with
215eb5604b0Swiz.Xr fsdb 8 .
216