The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 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:

  1. If the file does not exist:

    1. If the -f option is not specified, write a diagnostic message to standard error.

    2. Go on to any remaining files.

  2. If file is of type directory, the following steps are taken:

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

    2. 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.

    3. 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.

    4. 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.

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

  4. If the current file is a directory, rm will perform actions equivalent to the XSH specification rmdir() function called with a pathname of the current file used as the path argument. If the current file is not a directory, rm will perform actions equivalent to the XSH specification unlink() function called with a pathname of the current file used as the path argument.

    If this fails for any reason, rm will 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 -i option will be ignored.
-i
Prompt for confirmation as described previously. Any previous occurrences of the -f option 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 LANG is 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:
0
If the -f option was not specified, all the named directory entries were removed; otherwise, all the existing named directory entries were removed.
>0
An error occurred.

 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

  1. The following command:
    
    rm a.out core
    
    
    removes the directory entries: a.out and core.

  2. The following command:
    
    rm -Rf junk
    
    
    removes the directory junk and all its contents, without prompting.

 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, the XSH specification description of remove(), unlink().

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]