Skip to content

rm command in UNIX

Terminal window
rm [OPTION]... [FILE]...

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:

Terminal window
rm -rf DIRECTORY

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

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)

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

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

Manual reference: