• Subscription

    Fill out the form below to signup to our blog newsletter and we'll drop you a line when new articles come up.

    Our strict privacy policy keeps your email address 100% safe & secure.

  • Recent Posts

    • Exploited VPS? phpmyadmin?
    • Old versions of PHPMyAdmin and Automated Scanning
    • WordPress Mass Upgrade Script 3.0.1
    • Pingability Facelift
    • 66% off .org domain name registration anyone?
  • Categories

  • Facebook

  • Archives

  • Meta

Safe rm prevents accidents! try it!

September 21st, 2009 by Liz Quilty

I found this the today http://www.safe-rm.org.nz/ , and having had the odd accident im most definitely going to be installing this on my own server!

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.

So, why not install this on your server and save yourself some hassles in case you accidentally have that shell script gone wrong problem. Now if somebody could do the same to fdisk I would be totally happy, there was this time when i accidentally repartitioned my own server HDD after puting a new one in, and got the wrong drive :/

For manual install its as simple as

wget the file http://safe-rm.googlecode.com/files/safe-rm-0.6.tar.gz

tar zvxf safe-rm-0.6.tar.gz

cd safe-rm-0.6

mv /bin/rm /bin/old-rm

mv safe-rm /bin/rm

For those running debian variants you can

apt-get install safe-rm

Points to note in the README:

Once you have installed safe-rm on your system (see INSTALL), you will need to
fill the system-wide or user-specific blacklists with the paths that you’d like
to protect against accidental deletion.

The system-wide blacklist lives in /etc/safe-rm.conf and you should probably add
paths like these:

/
/etc
/usr
/usr/lib
/var

The user-specific blacklist lives in ~/.safe-rm and could include things like:

/home/username/documents
/home/username/documents/*
/home/username/.mozilla

Here are two projects which allow you to recover recently deleted files by trapping
all unlink(), rename() and open() system calls through the LD_PRELOAD facility:

delsafe (link in the readme is dead but i googled and updated it here)
http://unix.freshmeat.net/projects/delsafe

libtrashcan
http://hpux.connect.org.uk/hppd/hpux/Development/Libraries/libtrash-0.2/readme.html

There are also projects which implement the FreeDesktop.org trashcan spec. For example:

trash-cli
http://code.google.com/p/trash-cli

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

2 Responses to “Safe rm prevents accidents! try it!”

  1. Another excellent (and somewhat similar) tool is molly-guard: http://packages.debian.org/sid/molly-guard

    It’s designed to prevent accidental reboots of the wrong machine when accessing them remotely via ssh.

    When it detects an ssh session, it will prompt you for the machine name when using the “shutdown”, “reboot” or “halt” commands. Very handy!

  2. velofille Liz Quilty says:

    Ooo now that’s handy. I have before run the wrong commands on the wrong box before. Usually my own instead of somebody elses. I think we need to move back to inserting various brightly coloured blinking $PS1 lines :)

Leave a Reply

RimuHosting