Search an entire drive for character string

Steffen Kluge kluge at fujitsu.com.au
Tue Nov 15 07:38:21 UTC 2005


On Mon, 2005-11-14 at 22:54 -0700, David G. Miller (aka DaveAtFraud)
wrote:
> There is (was?) a hex editor for linux called bev that might do the 
> trick.  The problem with using dd and grep (e.g., dd if=/dev/hda | grep 
> 'string') is the best you will get is that the string you're interested 
> in is somewhere on the disk.

One could probably narrow it down to disk blocks, by checking them all
individually, like this:

$dev is the device to search
$size is the size of $dev in 1k blocks
$string is your search string

n=0; while [[ $n -lt $size ]]; do
  dd if=$dev bs=1k skip=$n count=1 2>/dev/null | \
  grep -q "$string" && echo Disk block $n matches.
  ((n=n+1))
done

Cheers
Steffen.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20051115/87b5e289/attachment-0001.sig>


More information about the fedora-list mailing list