Written on: 2005/09/24.

If you ever accidentally delete an important textual file permanently, Linux to the rescue!

Shut off the machine and get a Gentoo LiveCD. Boot the livecd and run grep -a -C 1000 "keyword" /dev/(insert storage device here, ex. hda1, sda1, etc) > restoration &.

Here's an explanation of how that command works and how you can customize it for your needs. The command basically scans the storage device you specify as a binary looking for the keyword you specify in plain text. It stores what it finds in a file called restoration.

Make sure your keyword is VERY unique, or you'll get a lot of garbage.

The -C 1000 specifies how many lines above and below your keyword to include. This is important because you want to get the whole file. Not just a section of it.

The & at the end lets the command run in the background so you don't lose your terminal. You can run tail -f restoration to watch the progress of the search. You can also run ps aux to see if grep is still running when you think it's done.