RM(1) General Commands Manual RM(1)

rmremove directory entries

rm [-fiRr] file ...

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 (i.e., the final pathname component), 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, 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, 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, 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.

(c) For each entry contained in file, other than dot or dot-dot, the four steps listed here [(1)-(4)] shall be taken with the entry as if it were a file operand. (d) If the −i option 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.

  1. 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, 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.

The rm utility shall be able to descend to arbitrary depths in a file hierarchy, and shall not fail due to path length limitations (unless an operand specified by the user exceeds system limitations).

The rm utility shall conform to the utility argument syntax guidelines described in 2.10.2.

The following options shall be supported by the implementation:

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.

Prompt for confirmation as described in AND 4.53.3. THE PROMPTS SHALL CONTAIN THE FILE PATHNAME, BUT THEIR FORMAT . Any previous occurrences of the −f option shall be ignored.

Remove file hierarchies. See AND 4.53.3. THE PROMPTS SHALL CONTAIN THE FILE PATHNAME, BUT THEIR FORMAT .

Equivalent to −R.

The following operand shall be supported by the implementation:

file

A pathname of a directory entry to be removed.

Used to read an input line in response to each prompt specified in STANDARD OUTPUT . Otherwise, the standard input shall not be used.

None.

The following environment variables shall affect the execution of rm:

This variable shall determine the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_ ) do not specify a locale. See 2.6.

This variable shall determine the locale to be used to override any values for locale categories specified by the settings of LANG or any environment variables beginning with LC_.

This variable shall determine the locale for the behavior of ranges, equivalence classes, and multicharacter collating elements used in the extended regular expression defined for the yesexpr locale keyword in the LC_MESSAGES category.

This variable shall determine the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte 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.

This variable shall determine the processing of affirmative responses and the language in which messages should be written.

Default.

None.

Prompts shall be written to standard error under the conditions specified in

is otherwise unspecified. The standard error shall also be used for diagnostic messages.

None.

None.

The rm utility shall exit with one of the following values:

If the −f option was not specified, all the named directory entries were removed; otherwise, all the existing named directory entries were removed.

An error occurred.

Default.

The requires that systems do not permit the removal of the last link to an executable binary file that is being executed. 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.

For absolute clarity, paragraphs (2)(b) and (3) in AND 4.53.3. THE PROMPTS SHALL CONTAIN THE FILE PATHNAME, BUT THEIR FORMAT , describing rm ’s behavior when prompting for confirmation, should be interpreted in the following manner: if (( f_option) AND ((not_writable AND input_is_terminal) OR i_option)) It is forbidden to remove the names dot and dot-dot in order to avoid the consequences of inadvertently doing something like: rm −r .∗ The following command rm a.out core removes the directory entries a.out and core. The following command rm -Rf junk removes the directory junk and all its contents, without prompting.

The exact format of the interactive prompts is unspecified. Only the general nature of the contents of prompts are specified, because implementations may desire more descriptive prompts than those used on historical implementations. Therefore, an application not using the −f option, or using the −i option relies on the system to provide the most suitable dialogue directly with the user, based on the behavior specified. The −r option is existing practice on all known systems. The synonym −R option is provided for consistency with the other utilities in this standard that provide options requesting recursive descent. The behavior of the −f option in historical versions of rm is inconsistent. In general, along with ‘‘forcing’’ the unlink without prompting for permission, it always causes diagnostic messages to be suppressed and the exit status to be unmodified for nonexistent operands and files that cannot be unlinked. In some versions, however, the −f option suppresses usage messages and system errors as well. Suppressing such messages is not a service to either shell scripts or users.

It is less clear that error messages regarding unlinkable files should be suppressed. Although this is historical practice, this standard does not permit the −f option to suppress such messages. When given the −r and −i options, historical versions of rm prompt the user twice for each directory, once before removing its contents and once before actually attempting to delete the directory entry that names it. This allows the user to ‘‘prune’’ the file hierarchy walk. Historical versions of rm were inconsistent in that some did not do the former prompt for directories named on the command line and others had obscure prompting behavior when the −i option was specified and the permissions of the file did not permit writing. The POSIX. 2 rm differs little from historic practice, but does require that prompts be consistent. Historical versions of rm were also inconsistent in that prompts were done to both standard output and standard error. POSIX. 2 requires that prompts be done to standard error, for consistency with cp and mv and to allow existing extensions to rm that provide an option to list deleted files on standard output. The rm utility is required to descend to arbitrary depths so that any file hierarchy may be deleted. This means, for example, that the rm utility cannot run out of file descriptors during its descent, i.e., if the number of file descriptors is limited, rm cannot be implemented in the historical fashion where a file descriptor is used per directory level. Also, rm is not permitted to fail because of path length restrictions, unless an operand specified by the user is longer than .

September 1991 posix.fail