Is it safe to alias rm to safe-rm?

We are happy to use safe-rm as a replacement to rm, but is it considered safe to alias it?

e.g.

alias rm='safe-rm'

2 Answers

Yes, an alias is just a shell-only rename. The scope of an alias is only the shell that you are currently in. safe-rm is just a wrapper that does some blacklist checking to prune the arguments list, it still calls rm under the hood (it also calls rm explicitly with /bin/rm so the alias does not affect the script)

It is not, however, safe in that it does not prevent a user from using rm explicitly either by unsetting the alias or by explicitly calling /bin/rm. safe-rm is only to prevent accidents, not a security feature, this is what permissions are for. You can still easily delete blacklisted files if you actually want to do that.


This is an extra tip

To avoid a mistaken rm -rf, do not type rm -rf.

  • If necessary, change to the parent of the directory you want to delete.
  • mv directory-to-delete DELETE
  • Explore DELETE and check that it is indeed what you wanted to delete
  • rm -rf DELETE

Never call rm -rf with an argument other than DELETE. Doing the deletion in several stages gives you an opportunity to verify that you aren't deleting the wrong thing, either because of a typo (as in rm -rf /foo /bar instead of rm -rf /foo/bar) or because of a braino (oops, no, I meant to delete foo.old and keep foo.new).

If your problem is that you can't trust others not to type rm -rf, consider removing their admin privileges. There's a lot more that can go wrong than rm.

Let me get into the problem you asked

This tool, safe-rm, ships with a default system-wide configuration file (/etc/safe-rm.conf), but each user can supplement that list of "protected" directories and files by adding lines to ~/.safe-rm.

Use \rm when you are sure about what you are deleting but most of the time, I prefer to go through the confirmation. Too many files disappeared because of a rushed removal action.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like