Grep binary string

A co-worker asked me if it is possible to grep arbitrary binary strings, e.g. sequences of non-printable ASCII characters. It turns out that GNU grep does understand binary strings if we use Perl-regex via the -P option.

[sh@pc ~]$ grep -slrP '\x05\x00\xc0' /boot

I couldn’t find this when Googling for “grep binary” so I thought I should pen it down here.

Posted in hacks. Tags: , . Leave a Comment »