rm (1)
PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.NAME
rm --- remove directory entriesSYNOPSIS
rm [-fiRr] file...
DESCRIPTION
The rm utility shall remove the directory entry specified by each file argument. If either of the files dot or dot-dot are specified as the basename portion of an operand (that is, the final pathname component) or if an operand resolves to the root directory, rm shall write a diagnostic message to standard error and do nothing more with such operands. For each file the following steps shall be taken:- 1.
-
If the
file
does not exist:
-
- a.
- If the -f option is not specified, rm shall write a diagnostic message to standard error.
- b.
- Go on to any remaining files.
-
- 2.
-
If
file
is of type directory, the following steps shall be taken:
-
- a.
- If neither the -R option nor the -r option is specified, rm shall write a diagnostic message to standard error, do nothing more with file, and go on to any remaining files.
- b.
- If the -f option is not specified, and either the permissions of file do not permit writing and the standard input is a terminal or the -i option is specified, rm shall write a prompt to standard error and read a line from the standard input. If the response is not affirmative, rm shall do nothing more with the current file and go on to any remaining files.
- c.
- For each entry contained in file, other than dot or dot-dot, the four steps listed here (1 to 4) shall be taken with the entry as if it were a file operand. The rm utility shall not traverse directories by following symbolic links into other parts of the hierarchy, but shall remove the links themselves.
- d.
- If the -i option is specified, rm shall write a prompt to standard error and read a line from the standard input. If the response is not affirmative, rm shall do nothing more with the current file, and go on to any remaining files.
-
- 3.
- If file is not of type directory, the -f option is not specified, and either the permissions of file do not permit writing and the standard input is a terminal or the -i option is specified, rm shall write a prompt to the standard error and read a line from the standard input. If the response is not affirmative, rm shall do nothing more with the current file and go on to any remaining files.
- 4.
-
If the current file is a directory,
rm
shall perform actions equivalent to the
rmdir()
function defined in the System Interfaces volume of POSIX.1-2008 called with a pathname of the current
file used as the
path
argument. If the current file is not a directory,
rm
shall perform actions equivalent to the
unlink()
function defined in the System Interfaces volume of POSIX.1-2008 called with a pathname of the current
file used as the
path
argument.
-
If this fails for any reason, rm shall write a diagnostic message to standard error, do nothing more with the current file, and go on to any remaining files.
-
OPTIONS
The rm utility shall conform to the Base Definitions volume of POSIX.1-2008, Section 12.2, Utility Syntax Guidelines. The following options shall be supported:- -f
- Do not prompt for confirmation. Do not write diagnostic messages or modify the exit status in the case of nonexistent operands. Any previous occurrences of the -i option shall be ignored.
- -i
- Prompt for confirmation as described previously. Any previous occurrences of the -f option shall be ignored.
- -R
- Remove file hierarchies. See the DESCRIPTION.
- -r
- Equivalent to -R.
OPERANDS
The following operand shall be supported:- file
- A pathname of a directory entry to be removed.
STDIN
The standard input shall be used to read an input line in response to each prompt specified in the STDOUT section. Otherwise, the standard input shall not be used.INPUT FILES
None.ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of rm:- LANG
- Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1-2008, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)
- LC_ALL
- If set to a non-empty string value, override the values of all the other internationalization variables.
- LC_COLLATE
-
Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements used in the extended regular expression defined for the yesexpr locale keyword in the LC_MESSAGES category. - LC_CTYPE
- Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments) and the behavior of character classes within regular expressions used in the extended regular expression defined for the yesexpr locale keyword in the LC_MESSAGES category.
- LC_MESSAGES
-
Determine the locale used to process affirmative responses, and the locale used to affect the format and contents of diagnostic messages and prompts written to standard error. - NLSPATH
- Determine the location of message catalogs for the processing of LC_MESSAGES.
ASYNCHRONOUS EVENTS
Default.STDOUT
Not used.STDERR
Prompts shall be written to standard error under the conditions specified in the DESCRIPTION and OPTIONS sections. The prompts shall contain the file pathname, but their format is otherwise unspecified. The standard error also shall be used for diagnostic messages.OUTPUT FILES
None.EXTENDED DESCRIPTION
None.EXIT STATUS
The following exit values shall be returned:- 0
- Each directory entry was successfully removed, unless its removal was canceled by a non-affirmative response to a prompt for confirmation.
- >0
- An error occurred.
CONSEQUENCES OF ERRORS
Default.The following sections are informative.
APPLICATION USAGE
The rm utility is forbidden to remove the names dot and dot-dot in order to avoid the consequences of inadvertently doing something like:
-
rm -r .*
EXAMPLES
- 1.
-
The following command:
-
-
rm a.out core
-
-
- 2.
-
The following command:
-
-
rm -Rf junk
-
-
RATIONALE
For absolute clarity, paragraphs (2b) and (3) in the DESCRIPTION of rm describing the behavior when prompting for confirmation, should be interpreted in the following manner:
-
if ((NOT f_option) AND ((not_writable AND input_is_terminal) OR i_option))
FUTURE DIRECTIONS
None.SEE ALSO
rmdir The Base Definitions volume of POSIX.1-2008, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines The System Interfaces volume of POSIX.1-2008, remove(), rmdir(), unlink()COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, Copyright (C) 2013 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. (This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the event of any discrepancy between this version 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 www.unix.org/online.html .Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see www.kernel.org/doc/man-pages/reporting_bugs.html .