Recovering text files in terminal using grep on Mac OS X Snow Leopard

I foolishly removed some source code from my Mac OS X Snow Leopard machine with rm -rf when doing something with buildout. I want to try and recover these files again. I haven't touched the system since to try and seek an answer.

I found this article and it seems like the grep method is the way to go, but when running it on my machine I'm getting 'Resource busy' when trying to run it on the disk.

I'm using this command:

sudo grep -a -B1000 -A1000 'video_output' /dev/disk0s2 > file.txt

Where 'dev/disk0s2' is what came up when I ran df.

I get this when running:

grep: /dev/disk0s2: Resource busy

I'm not an expert with this stuff, I'm trying my best. Please can anyone help me further? I'm on the verge of losing two days of source code work!

Thank you


Try this with an Ubuntu LiveCD (here) or GPartEd boot CD (here) or something similar where you can boot from CD and not your hard drive partition (assuming you have another computer where you can download and burn one of those). Even if they don't understand the HFS+ file system they will be able to read it in raw format.

This will be the safest way. For once, the operating system will not lock the drive and you won't run into the risk tha the swap file or temp files will overwrite the precious free blocks.


Once you boot to some other device you'll need to keep in mind that if you are grepping for the filename you might not be getting what you want since the file name isn't in the file itself - unless you included it in comments or something.

You'll need to grep for some phrase that you know is in the file.