Home » Questions » Computers [ Ask a new question ]

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

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.

Asked by: Guest | Views: 347
Total answers/comments: 1
Guest [Entry]

"You will have to grep the disk instead of the disk slice. Using my machine as an example,

$ diskutil list
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *240.1 GB disk0
1: EFI EFI 209.7 MB disk0s1
2: Apple_HFS Sandisk 240G 239.2 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3

disk0 is the entire disk, and disk0s2 is the partition where I deleted the file. Grep does not work on disk slice

$ sudo grep --binary-files=text --context=10 '192.168.1.196' /dev/disk0s2 > recovered.txt
Password:
grep: /dev/disk0s2: Resource busy

But works on the disk itself

$ sudo grep --binary-files=text --context=10 '192.168.1.196' /dev/disk0 > recovered.txt

Caution

grep'ing raw disks in OSX does not work - and will crash OSX. When I ran the command above, Activity Monitor shows grep reading data rapidly. After reading about 3GB, OSX hung and I had to reboot."