rm — Remove a directory entry

Format

rm [–fiRrv] file …file …

Description

rm removes files (provided that 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, rm asks you if you are sure you want to delete the file; type the yes expression defined in LC_MESSAGES (the English expression is typically y or yes) if you really want it deleted.

Restriction: A file can be removed by any user who has write permission to the directory containing 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.
Tip: f you delete a file, remember that the space is not actually reclaimed until any processes that have that file open either terminate or close that file. See the fuser — List process IDs of processes with open files command to find out how to get more information about what processes are accessing a particular file or directory.

Options

–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 and 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 will not issue an error.
–i
Prompts you for confirmation before deleting each 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.
–R
Recursively removes the entire directory structure if file is a directory.
–r
Is equivalent to –R.
–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

See Localization for more information.

Exit values

0
Successful completion
1
Failure due to any of the following:
  • 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:
  • Incorrect command-line option
  • No file was specified

Portability

POSIX.2, X/Open Portability GuideUNIX systems.

Related information

cp, mv, rmdir