NAME
rm — remove
directory entries
SYNOPSIS
rm |
[-fiRr] file... |
DESCRIPTION
The rm utility removes 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),
rm will write a diagnostic message to standard error
and do nothing more with such operands.
For each file the following steps are taken:
- If the file does not exist:
- If the
-foption is not specified, write a diagnostic message to standard error.Go on to any remaining files.
- If file is of type directory, the following steps are taken:
- If neither the
-Roption nor the-roption is specified, write a diagnostic message to standard error, do nothing more with file, and go on to any remaining files.If the
-foption is not specified, and either the permissions of file do not permit writing and the standard input is a terminal or the-ioption is specified, write a prompt to standard error and read a line from the standard input. If the response is not affirmative, do nothing more with the current file and go on to any remaining files.For each entry contained in file, other than dot or dot-dot, the four steps listed here (1-4) are taken with the entry as if it were a file operand.
If the
-ioption is specified, write a prompt to standard error and read a line from the standard input. If the response is not affirmative, do nothing more with the current file, and go on to any remaining files. - If file is not of type directory, the
-foption is not specified, and either the permissions of file do not permit writing and the standard input is a terminal or the-ioption is specified, write a prompt to the standard error and read a line from the standard input. If the response is not affirmative, do nothing more with the current file and go on to any remaining files. - If the current file is a directory,
rmwill perform actions equivalent to the XSH specification rmdir(3) function called with a pathname of the current file used as the path argument. If the current file is not a directory,rmwill perform actions equivalent to the XSH specification unlink(3) function called with a pathname of the current file used as the path argument. - If this fails for any reason,
rmwill write a diagnostic message to standard error, do nothing more with the current file, and go on to any remaining files.
The rm utility is able to descend to
arbitrary depths in a file hierarchy, and will not fail due to path length
limitations (unless an operand specified by the user exceeds system
limitations).
OPTIONS
The rm utility supports the XBD
specification,
Utility
Syntax Guidelines . The following options are supported:
- -f
- Do not prompt for confirmation. Do not write diagnostic messages or modify
the exit status in the case of non-existent operands. Any previous
occurrences of the
-ioption will be ignored. - -i
- Prompt for confirmation as described previously. Any previous occurrences
of the
-foption will be ignored. - -R
- Remove file hierarchies. See the DESCRIPTION section.
- -r
- Equivalent to
-R.
OPERANDS
The following operand is supported:
- file
- A pathname of a directory entry to be removed.
STDIN
Used to read an input line in response to each prompt specified in the STDOUT section. Otherwise, the standard input will not be used.
INPUT FILES
None.
ENVIRONMENT VARIABLES
The following environment variables affect the execution of
rm :
LANG- Provide a default value for the internationalisation variables that are
unset or null. If
LANGis unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL- If set to a non-empty string value, override the values of all the other internationalisation variables.
LC_COLLATE- Determine the locale for the behaviour 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- versus multi-byte characters in arguments) and the behaviour 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 for the processing of affirmative responses that should be used to affect the format and contents of diagnostic messages written to standard error.
NLSPATH- Determine the location of message catalogues for the processing of LC_MESSAGES .
ASYNCHRONOUS EVENTS
Default.
STDOUT
Not used.
STDERR
Prompts are written to standard error under the conditions specified in the DESCRIPTION and OPTIONS sections. The prompts will contain the file pathname, but their format is otherwise unspecified. The standard error is also used for diagnostic messages.
OUTPUT FILES
None.
EXTENDED DESCRIPTION
None.
EXIT STATUS
The following exit values are returned:
CONSEQUENCES OF ERRORS
Default.
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 .*
Some systems do not permit the removal of the last link
to an executable binary file that is being executed; see the [EBUSY] error
in the XSH
specification
unlink()
description. Thus, the rm utility can fail to remove
such files.
The -i option causes
rm to prompt and read the standard input even if the
standard input is not a terminal, but in the absence of
-i the mode prompting is not done when the standard
input is not a terminal.
EXAMPLES
- The following command:
removes the directory entries: a.out and core .
rm a.out core
- The following command:
removes the directory junk and all its contents, without prompting.
rm -Rf junk
FUTURE DIRECTIONS
The IEEE PASC 1003.2 Interpretations Committee has forwarded concerns about parts of this interface definition to the IEEE PASC Shell and Utilities Working Group which is identifying the corrections. A future revision of this specification will align with IEEE Std. 1003.2b when finalised.
SEE ALSO
rmdir(1) , the XSH specification description of remove(3) , unlink(3) .