.\" .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for .\" permission to reproduce portions of its copyrighted documentation. .\" Original documentation from The Open Group can be obtained online at .\" http://www.opengroup.org/bookstore/. .\" .\" The Institute of Electrical and Electronics Engineers and The Open .\" Group, have given us permission to reprint portions of their .\" documentation. .\" .\" In the following statement, the phrase ``this text'' refers to portions .\" of the system documentation. .\" .\" Portions of this text are reprinted and reproduced in electronic form .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, .\" Standard for Information Technology -- Portable Operating System .\" Interface (POSIX), The Open Group Base Specifications Issue 6, .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics .\" Engineers, Inc and The Open Group. In the event of any discrepancy .\" between these versions and the original IEEE and The Open Group .\" Standard, the original IEEE and The Open Group Standard is the referee .\" document. The original Standard can be obtained online at .\" http://www.opengroup.org/unix/online.html. .\" .\" This notice shall appear on any product containing this material. .\" .\" The contents of this file are subject to the terms of the .\" Common Development and Distribution License (the "License"). .\" You may not use this file except in compliance with the License. .\" .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE .\" or http://www.opensolaris.org/os/licensing. .\" See the License for the specific language governing permissions .\" and limitations under the License. .\" .\" When distributing Covered Code, include this CDDL HEADER in each .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. .\" If applicable, add the following below this CDDL HEADER, with the .\" fields enclosed by brackets "[]" replaced with your own identifying .\" information: Portions Copyright [yyyy] [name of copyright owner] .\" .\" .\" Copyright 1989 AT&T .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved .\" .Dd July 3, 2017 .Dt RM 1 .Os .Sh NAME .Nm rm , .Nm rmdir .Nd remove directory entries .Sh SYNOPSIS .Nm /usr/bin/rm .Op Fl f .Op Fl i .Ar .Pp .Nm /usr/bin/rm .Fl rR .Op Fl f .Op Fl i .Ar dirname ... .Op Ar file ... .Pp .Nm /usr/xpg4/bin/rm .Op Fl fiRr .Ar .Pp .Nm /usr/bin/rmdir .Op Fl ps .Ar dirname .Ss "ksh93" .Nm /usr/bin/rmdir .Op Fl eps .Ar dirname ... .Sh DESCRIPTION .Ss "/usr/bin/rm /usr/xpg4/bin/rm" The .Nm rm utility removes the directory entry specified by each .Ar file argument. If a file has no write permission and the standard input is a terminal, the full set of permissions (in octal) for the file are printed followed by a question mark. This is a prompt for confirmation. If the answer is affirmative, the file is deleted, otherwise the file remains. .Pp If .Ar file is a symbolic link, the link is removed, but the file or directory to which it refers is not deleted. Users do not need write permission to remove a symbolic link, provided they have write permissions in the directory. .Pp If multiple .Ar file Ns s are specified and removal of a .Ar file fails for any reason, .Nm rm writes a diagnostic message to standard error, do nothing more to the current .Ar file , and go on to any remaining .Ar file Ns s . .Pp If the standard input is not a terminal, the utility operates as if the .Fl f option is in effect. .Ss "/usr/bin/rmdir" The .Nm rmdir utility removes the directory entry specified by each .Ar dirname operand, which must refer to an empty directory. .Pp Directories are processed in the order specified. If a directory and a subdirectory of that directory are specified in a single invocation of .Nm rmdir , the subdirectory must be specified before the parent directory so that the parent directory is empty when .Nm rmdir tries to remove it. .Ss "ksh93" The .Nm rmdir built-in in .Nm ksh93 is associated with the .Pa /bin and .Pa /usr/bin paths. It is invoked when .Nm rmdir is executed without a pathname prefix and the pathname search finds a .Pa /bin/rmdir or .Pa /usr/bin/rmdir executable. .Pp .Nm rmdir deletes each given directory. The directory must be empty and contain no entries other than .Pa \&. or .Pa .. . If a directory and a subdirectory of that directory are specified as operands, the subdirectory must be specified before the parent, so that the parent directory is empty when .Nm rmdir attempts to remove it. .Sh OPTIONS The following options are supported for .Nm /usr/bin/rm and .Nm /usr/xpg4/bin/rm : .Bl -hang .It Fl r Recursively removes directories and subdirectories in the argument list. The directory is emptied of files and removed. The user is normally prompted for removal of any write-protected files which the directory contains. The write-protected files are removed without prompting, however, if the .Fl f option is used, or if the standard input is not a terminal and the .Fl i option is not used. .Pp Symbolic links that are encountered with this option is not traversed. .Pp If the removal of a non-empty, write-protected directory is attempted, the utility always fails (even if the .Fl f option is used), resulting in an error message. .It Fl R Same as .Fl r option. .El .Ss "/usr/bin/rm" The following options are supported for .Nm /usr/bin/rm only: .Bl -hang .It Fl f Removes all files (whether write-protected or not) in a directory without prompting the user. In a write-protected directory, however, files are never removed (whatever their permissions are), but no messages are displayed. If the removal of a write-protected directory is attempted, this option does not suppress an error message. .It Fl i Interactive. With this option, .Nm rm prompts for confirmation before removing any files. It overrides the .Fl f option and remains in effect even if the standard input is not a terminal. .El .Ss "/usr/xpg4/bin/rm" The following options are supported for .Nm /usr/xpg4/bin/rm only: .Bl -hang .It Fl f Does not prompt for confirmation. Does not write diagnostic messages or modify the exit status in the case of non-existent operands. Any previous occurrences of the .Fl i option is ignored. .It Fl i Prompts for confirmation. Any occurrences of the .Fl f option is ignored. .El .Ss "/usr/bin/rmdir" The following options are supported for .Nm /usr/bin/rmdir only: .Bl -hang .It Fl p Allows users to remove the directory .Ar dirname and its parent directories which become empty. A message is printed to standard error if all or part of the path could not be removed. .It Fl s Suppresses the message printed on the standard error when .Fl p is in effect. .El .Ss "ksh93" The following options are supported for the .Nm rmdir built-in for .Nm ksh93 : .Pp .Bl -hang -compact .It Fl e .It Fl -ignore-fail-on-non-empty Ignore each non-empty directory failure. .El .Pp .Bl -hang -compact .It Fl p .It Fl -parents Remove each explicit directory argument directory that becomes empty after its child directories are removed. .El .Pp .Bl -hang -compact .It Fl s .It Fl -suppress Suppress the message printed on the standard error when .Fl p is in effect. .El .Sh OPERANDS The following operands are supported: .Bl -tag -width Ar .It Ar file Specifies the pathname of a directory entry to be removed. .It Ar dirname Specifies the pathname of an empty directory to be removed. .El .Sh USAGE See .Xr largefile 5 for the description of the behavior of .Nm rm and .Nm rmdir when encountering files greater than or equal to 2 Gbyte (2^31 bytes). .Sh EXIT STATUS The following exit values are returned: .Bl -tag -width Sy .It Sy 0 If the .Fl f option was not specified, all the named directory entries were removed; otherwise, all the existing named directory entries were removed. .It Sy >0 An error occurred. .El .Ss "ksh93" The following exit values are returned: .Bl -tag -width Sy .It Sy 0 Successful completion. All directories deleted successfully. .It Sy >0 An error occurred. One or more directories could not be deleted. .El .Sh EXAMPLES The following examples are valid for the commands shown. .Ss "/usr/bin/rm, /usr/xpg4/bin/rm" .Bl -ohang .It Sy Example 1 No Removing Directories .Pp The following command removes the directory entries .Pa a.out and .Pa core : .Pp .Dl example% rm a.out core .El .Bl -ohang .It Sy Example 2 No Removing a Directory without Prompting .Pp The following command removes the directory .Pa junk and all its contents, without prompting: .Pp .Dl example% rm -rf junk .El .Ss "/usr/bin/rmdir" .Bl -ohang .It Sy Example 3 No Removing Empty Directories .Pp If a directory .Pa a in the current directory is empty, except that it contains a directory .Pa b , and .Pa a/b is empty except that it contains a directory .Pa c , the following command removes all three directories: .Pp .Dl example% rmdir -p a/b/c .El .Sh DIAGNOSTICS All messages are generally self-explanatory. .Pp It is forbidden to remove the files .Qq Pa \&. and .Qq Pa .. in order to avoid the consequences of inadvertently doing something like the following: .Pp .Dl example% rm -r .* .Pp It is forbidden to remove the file .Qq Pa / in order to avoid the consequences of inadvertently doing something like: .Pp .Dl example% rm -rf $x/$y .Pp or .Pp .Dl example% rm -rf /$y .Pp when .Va $x and .Va $y expand to empty strings. .Sh ENVIRONMENT VARIABLES See .Xr environ 5 for descriptions of the following environment variables that affect the execution of .Nm rm and .Nm rmdir : .Ev LANG , .Ev LC_ALL , .Ev LC_COLLATE , .Ev LC_CTYPE , .Ev LC_MESSAGES , and .Ev NLSPATH . .Pp Affirmative responses are processed using the extended regular expression defined for the .Sy yesexpr keyword in the .Ev LC_MESSAGES category of the user's locale. The locale specified in the .Ev LC_COLLATE category defines the behavior of ranges, equivalence classes, and multi-character collating elements used in the expression defined for .Sy yesexpr . The locale specified in .Ev LC_CTYPE determines the locale for interpretation of sequences of bytes of text data a characters, the behavior of character classes used in the expression defined for the .Sy yesexpr . See .Xr locale 5 . .Sh INTERFACE STABILITY .Ss "/usr/xpg4/bin/rm" Committed .Ss "ksh93" The .Nm ksh93 built-in binding to .Pa /bin and .Pa /usr/bin is Volatile. The built-in interfaces are Uncommitted. .Sh SEE ALSO .Xr ksh93 1 , .Xr rmdir 2 , .Xr rmdir 2 , .Xr unlink 2 , .Xr attributes 5 , .Xr environ 5 , .Xr largefile 5 , .Xr standards 5 .Sh NOTES A .Fl permits the user to mark explicitly the end of any command line options, allowing .Nm rm to recognize file arguments that begin with a .Fl . As an aid to BSD migration, .Nm rm accepts .Fl - as a synonym for .Fl . This migration aid may disappear in a future release. If a .Fl - and a .Fl both appear on the same command line, the second is interpreted as a file.