It happens, you accidentally delete a file and you need it back. Maybe you don’t do backups (shame on you). Maybe your most current backup isn’t good enough. Whatever the reason many people, myself included, have accidentally removed something that they need back. Here is a quick trick that might save you.
grep -a -B 25 -A 100 'some string in the file' /dev/sda1 > results.txt
“-a” – treat the drive (binary) as text
“-B 25 -A 100″ – print 25 lines before a match and 100 lines after
The search string must be something you know was in the file you removed that is likely to be unique.
It’s probably a good idea to write the output on a different partition than the one you are searching. You can also substitute something like “-C 100″ for the -B/-A switches. The -C switch is short hand for the arguement number of lines both before and after the match.
via Atomic Spin