| RM(1) | User Commands | RM(1) |
rm — remove
directory entries
/usr/bin/rm |
[-dfiv] target ... |
/usr/bin/rm |
-rR [-dfiv]
target ... |
/usr/xpg4/bin/rm |
[-fiRr] target ... |
The rm utility removes the directory entry
specified by each target 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. If standard input is not a terminal,
then the file is removed regardless.
If target 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.
If target is a directory, then it is not
removed by default. There are two exceptions here. If the
-r or -R option is
specified, then directories will be recursively descended into and removed.
If -d is specified and the directory is empty, then
the directory will be removed.
If multiple targets are specified and
removal of a target fails for any reason,
rm writes a diagnostic message to standard error, do
nothing more to the current target, and go on to any
remaining targets.
If the standard input is not a terminal, the utility operates as
if the -f option is in effect.
The following options are supported for both
/usr/bin/rm and
/usr/xpg4/bin/rm:
-d-r-f option is used, or if the
standard input is not a terminal and the -i option
is not used.
Symbolic links that are encountered with this option is not traversed.
If the removal of a non-empty, write-protected directory is
attempted, the utility always fails (even if the
-f option is used), resulting in an error
message.
-R-r option.-vThe following options are supported for
/usr/bin/rm only:
-f-irm prompts for
confirmation before removing any files. It overrides the
-f option and remains in effect even if the
standard input is not a terminal.The following options are supported for
/usr/xpg4/bin/rm only:
The following operands are supported:
See largefile(7) for the
description of the behavior of rm when encountering
files greater than or equal to 2 Gbyte (2^31 bytes).
The following exit values are returned:
Example 1 Removing Files
The following command removes the directory entries a.out and core:
example% rm a.out coreExample 2 Removing a Directory without Prompting
The following command removes the directory junk and all its contents, without prompting:
example% rm -rf junkExample 3 Removing Empty Directories
The following command removes an empty directory.
example% mkdir foo example% rm -d foo
Example 4 Printing Removed Contents
The following command prints the names of all files successfully removed to standard out.
example% rm -rv out/ test out/amd64/dtrace out/amd64 out test
All messages are generally self-explanatory.
It is forbidden to remove the files "." and ".." in order to avoid the consequences of inadvertently doing something like the following:
example% rm -r .*It is forbidden to remove the file "/" in order to avoid the consequences of inadvertently doing something like:
example% rm -rf $x/$yor
example% rm -rf /$ywhen $x and $y expand to empty strings.
See environ(7) for
descriptions of the following environment variables that affect the
execution of rm: LANG,
LC_ALL, LC_COLLATE,
LC_CTYPE, LC_MESSAGES, and
NLSPATH.
Affirmative responses are processed using the extended regular
expression defined for the yesexpr keyword in the
LC_MESSAGES category of the user's locale. The
locale specified in the LC_COLLATE category defines
the behavior of ranges, equivalence classes, and multi-character collating
elements used in the expression defined for yesexpr. The
locale specified in 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
yesexpr. See
locale(7).
Committed
The ksh93 built-in binding to
/bin and /usr/bin is
Volatile. The built-in interfaces are Uncommitted.
ksh93(1), rmdir(1), unlink(2), attributes(7), environ(7), largefile(7), standards(7)
A - permits the user to mark explicitly
the end of any command line options, allowing rm to
recognize file arguments that begin with a -. As an
aid to BSD migration, rm accepts
-- as a synonym for -. This
migration aid may disappear in a future release. If a
-- and a - both appear on
the same command line, the second is interpreted as a file.
| March 28, 2026 | OmniOS |