What is safe-rm?

Safe-rm is a safety tool intended to prevent the accidental deletion of important files by replacing /bin/rm with a wrapper, which checks the given arguments against a configurable blacklist of files and directories that should never be removed.

Users who attempt to delete one of these protected files or directories will not be able to do so and will be shown a warning message instead:

    $ rm -rf /usr
    Skipping /usr

(Protected paths can be set both at the site and user levels.)

Recovering important files you deleted by mistake can be quite hard. Protect yourself today by installing safe-rm and reduce the likelihood that you will need to contact a data recovery service!

from Google Code (Linux/UNIX source code).

2008-06-08

safe-rm 0.1 released

As mentioned on the debian-devel mailing list, I recently deleted my /usr/lib by mistake and had to go through the pain of reinstalling all of my Debian packages. So I wrote a little Perl script which I have now aliased to "rm" in my .bashrc.

Basically, the wrapper has a blacklist which contains directories like /usr/lib, /home, /etc and removes those before passing its arguments to the real 'rm' command.

I'm probably not the only person to have made this mistake and who wants to avoid doing it again. So I'm thinking of turning it into something that's useful to other people (probably packaging it in some form).

I realize that 'rm' is a low-level command which should do what it's told, but the reality is that a lot of people use it directly on a daily basis and can accidently hose their system. I don't want to implement a "command-line trashcan", but I'm looking for a way to prevent me from doing things I should never ask for (like 'rm -rf /usr/lib/').
Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 New Zealand License.