We are happy to use
safe-rm as a replacement to
rm, but is it considered safe to alias it?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
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.
To avoid a mistaken
rm -rf, do not type
mv directory-to-delete DELETE
DELETEand check that it is indeed what you wanted to delete
rm -rf DELETE
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
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
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.
\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.