rm - Remove a directory entry
Format
rm [-FfiPRrv] file ... file ...
Description
rm removes files if it is a valid path name. If you specify either
.
or ..
as the final component of the path name for a
file, rm displays an error message and goes to the next
file. If a file does not have write permission set, you are asked if you want to delete the file.
Type the yes
expression that is defined in LC_MESSAGES (the English expression is
typically y
or yes
) if you want it deleted.
If you delete a file, the space is not reclaimed until any processes that have that file open either terminate or close that file. To find out how to get more information about what processes are accessing a particular file or directory, see fuser - List process IDs of processes with open files.
Options
- -F
- When removing a hierarchy recursively, skips directories in file systems that are different from that of the corresponding command-line argument. This is available with APAR OA60001.
- -f
- Deletes read-only files immediately without asking for confirmation. When you specify this option and a file does not exist, rm does not display an error message. It also does not modify the exit status. If you specify both -f and -i, rm uses the option that appears last on the command line. If no files are specified, rm -f does not issue an error.
- -i
- Prompts you for confirmation before deleting the file. If you specify both -R and -i, rm also prompts you for confirmation before deleting a directory. If you specify both -f and -i, rm uses the option that appears last on the command line.
- -P
- Does not remove '/' and rejects any command-line argument when the specified path is equal to the root directory. This is available with APAR OA60001.
- -r
- Is equivalent to -R.
- -R
- Recursively removes the entire directory structure if file is a directory.
- -v
- Displays a list of files that were removed.
Localization
- LANG
- LC_ALL
- LC_COLLATE
- LC_CTYPE
- LC_MESSAGES
- LC_SYNTAX
- NLSPATH
Usage notes
- The -F and -P options can prevent the accidental deletion of
root directory contents. Add an alias in your personal profile file to enable it as a default
behavior. For example,
alias "rm"="rm -PF"
. Then the rm command will prevent the deletion of root directory contents by default.
Exit values
0
- Successful completion.
1
- Failure due to any of the following reasons:
- Inability to remove a file.
- Attempt to remove directory without specifying -r or -R.
- Inability to find file information when using -r or -R.
- Inability to read directory when using -r or -R.
2
- Failure due to any of the following reasons:
- Incorrect command-line option.
- No file was specified.
Portability
POSIX.2, X/Open Portability GuideUNIX systems.
Related information
cp, mv, rmdir