1.\" $OpenBSD: rm.1,v 1.40 2016/04/15 23:09:57 tedu 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: April 15 2016 $ 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 dfiPRr 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 79Overwrite regular 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.El 99.Pp 100The 101.Nm 102utility removes symbolic links, not the files referenced by the links. 103.Pp 104It is an error to attempt to remove the root directory or the files 105.Dq \&. 106or 107.Dq .. . 108It is forbidden to remove the file 109.Dq .. 110merely to avoid the antisocial consequences of inadvertently 111doing something like 112.Dq Cm rm -r .* . 113.Sh EXIT STATUS 114The 115.Nm 116utility exits 0 if all of the named files or file hierarchies were removed, 117or if the 118.Fl f 119option was specified and all of the existing files or file hierarchies were 120removed. 121If an error occurs, 122.Nm 123exits with a value >0. 124.Sh EXAMPLES 125Recursively remove all files contained within the 126.Pa foobar 127directory hierarchy: 128.Pp 129.Dl $ rm -rf foobar 130.Pp 131Either of these commands will remove the file 132.Pa -f : 133.Bd -literal -offset indent 134$ rm -- -f 135$ rm ./-f 136.Ed 137.Sh SEE ALSO 138.Xr rmdir 1 , 139.\" .Xr undelete 2 , 140.Xr unlink 2 , 141.Xr fts 3 , 142.Xr symlink 7 143.Sh STANDARDS 144The 145.Nm 146utility is compliant with the 147.St -p1003.1-2008 148specification. 149.Pp 150The flags 151.Op Fl dP 152are extensions to that specification. 153.Sh HISTORY 154An 155.Nm 156command appeared in 157.At v1 . 158.Pp 159The 160.Nm 161utility differs from historical implementations in that the 162.Fl f 163option only masks attempts to remove non-existent files instead of 164masking a large variety of errors. 165.Pp 166Also, historical 167.Bx 168implementations prompted on the standard output, 169not the standard error output. 170.Pp 171The interactive mode used to be a 172.Nm dsw 173command, a carryover from the ancient past with an 174amusing etymology. 175.Sh BUGS 176The 177.Fl P 178option assumes that both the underlying file system and storage medium write 179in place. 180This is true for the FFS and MS-DOS file systems and magnetic hard disks, 181but not true for most flash storage. 182In addition, only regular files are overwritten; other types of files 183are not. 184