rm - Remove a directory entry

Format

Start of changerm [-FfiPRrv] file ... file ...End of change

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.

Restriction: A file can be removed by any user who has write permission to the directory that contains the file, unless that directory has its sticky bit turned on. If the file is in a directory whose sticky bit is turned on, only the file owner, the owner of the directory, or a superuser can remove the file.

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

Start of change-FEnd of change
Start of changeWhen 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.End of change
-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.
Start of change-PEnd of change
Start of changeDoes not remove '/' and rejects any command-line argument when the specified path is equal to the root directory. This is available with APAR OA60001.End of change
-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

rm uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_COLLATE
  • LC_CTYPE
  • LC_MESSAGES
  • LC_SYNTAX
  • NLSPATH

Usage notes

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