rm command in UNIX


rm [OPTION]... [FILE]...

Introduction

rm removes each specified file. By default, it does not remove directories.

If you need to remove a directory (below called DIRECTORY) and all its content you can’t use rmdir so you need to use this command:

rm -rf DIRECTORY

BE CAREFUL: you could delete your whole file system if you specify ‘./’ as DIRECTORY.

Options

The most useful options are:

  • -f, --force: ignore nonexistent files and arguments, never prompt
  • -i: prompt before every removal (type y to confirm, n to deny)
  • --no-preserve-root: do not treat '/' specially (very dangerous)
  • -r, -R, --recursive: remove directories and their contents recursively
  • -v, --verbose: explain what is being done (common to lots of commands)

Examples

The command above is often used to remove node_modules folder when working on a Node.js project.

rm -rf node_modules/

# if you hate yourself, use the verbose mode
rm -rfv node_modules/

Quotes

Manual reference: