100 Useful Command-Line Utilities

by Oliver; 2014

10. rm

The command rm removes the files you pass to it as arguments:
$ rm file     # removes a file
Use the recursive flag, -r, to remove a file or a directory:
$ rm -r dir   # removes a file or directory
If there's a permission issue or the file doesn't exist, rm will throw an error. You can override this with the force flag, -f:
$ rm -rf dir  # force removal of a file or directory
	      # (i.e., ignore warnings)
You may be aware that when you delete files, they can still be recovered with effort if your computer hasn't overwritten their contents. To securely delete your files—meaning overwrite them before deleting—use:
$ rm -P file  # overwrite your file then delete
or use shred.

<PREV   NEXT>