Bennyland this server is running in my bedroom – benny’s learning how to run a linux server

13Feb/100

Update: Creating a TrashCan for shell undelete

update: I updated this script so that it would put a number at the end of the file name if it already exists in the trash... it's a slow process (increment from 0 and test until you don't find an existing file) but it works :)

Original post follows:
so a couple of weeks ago I was up far later than I should have been and managed to run the following, as root, in the root directory /

rm -rf *

What I was trying to do is delete a bunch of backup files that my backup script had been sticking in the wrong location (the smart thing would have been to copy the wrongly placed backup files into the correct place, and also not use -rf, but i'm a noob)

So, as you can imagine, after about 2 seconds (the time it took me to realize what had just happened and instantly wake up) the server was foobared. Now that it's been a couple weeks I can actually marvel at how fast rm is, it literally deleted almost everything on the server (everything that wasn't running at least) in a matter of seconds, that's pretty impressive when you are use to deleting things in windows (and I almost always shift delete, a dangerous pattern emerges...)

Anyway, so I had to re-install the OS and everything else. Luckily I had a 5 day old backup of the web and svn contents, and some chrome caches of my blog (which had all of my instructions for getting the server back up and going) so I wasn't fully up a creek. After restoring everything I did some searching around and found a way to replace rm with a move to trash bash script which is complemented by a cron that runs to clean out old trash.

Here's how to get the same thing