Thursday, March 15, 2012

Recovering a Text File in Linux

 Did I ever tell you how thankful I am that I do most of my writing in a more or less plain text editor?

grep -a -A800 -B800 'obustness' /dev/sda5 | strings > recovered_file



Everyone loves grep
-a says to process binary as text
-A[number] tells grep to include 800 lines after the matching term is found
-B[number] tells grep to include 800 lines before the matching term is found
then of course you will want to supply a term for grep to match against
and finally where you want grep to look /dev/sda5 happens to be my /home partition




Then pipe all that off to strings to be redirected into a file.
The reason you would do that is because it will clean up some of the gobbledygook the -a option of grep will not.

--I figured that Robustness would be a somewhat rare string to search for. And I could make it case insensitive by just leaving off the 'R' (yes, it can be done with switches).

Interesting thing to note, people besides me use the word Robustness. Not as rare as I was hoping.

No comments:

Post a Comment

Followers