Rm (Unix) - Options

Options

Common options that rm accepts include:

  • -r, which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")
  • -i, which asks for every deletion to be confirmed ("interactive")
  • -f, which ignores non-existent files and overrides any confirmation prompts ("force"), although it will not remove files from a directory if the directory is write protected.

rm is often overlain by a C shell alias or Bourne shell function of "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence). Unfortunately this approach generates dangerous habits towards the use of wildcarding, leading to its own version of accidental removals.

rm -rf (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of nearly every writable mounted filesystem on the computer to be deleted, up to the point the system itself crashes from missing some crucial file, directory, or the like.

rm is often used in conjunction with xargs to supply a list of files to delete:

xargs rm < filelist

Or, to remove all PNG images in all directories below the current one:

find . -name '*.png' -print0 | xargs -0 rm

Read more about this topic:  Rm (Unix)