Binary Grep
See the codeI'm terribly annoyed by the fact that grep(1) cannot look for binary strings. I'm even more annoyed by the fact that a simple search for "binary grep" doesn't yield a tool which could do that. So I wrote one.
Feel free to modify, branch, fork, improve.
make
make install # to /user/local/bin, or
make install PREFIX=~/.local
Or, if you need it quickly,
curl -L 'https://github.com/tmbinc/bgrep/raw/main/bgrep.c' | gcc -O2 -x c -o $HOME/.local/bin/bgrep -
bgrep [-r] [-B bytes] [-A bytes] [-C bytes] <hex> [<path> [...]]
bgrep [-r] -f <pattern> [-m <mask>] [<path> [...]]
| Option | Description |
|---|---|
-B <bytes> | print <bytes> of context before each match |
-A <bytes> | print <bytes> of context after each match |
-C <bytes> | print <bytes> of context before and after a match |
-r | recurse into directories |
-f <file> | read the search pattern from a file instead of <hex> |
-m <file> | read a mask file (wildcard bytes for the pattern) |
When no path is given, bgrep reads from standard input.
Search a file for the byte sequence 0x42 0x42 0x42:
bgrep 424242 firmware.bin
Recurse through a directory:
bgrep -r 424242 ./images
BSD 2-Clause. See LICENSE.
108 followers · starred Mar 2019
650 followers · starred Jul 2016
31 followers · starred Dec 2016
162 followers · starred Feb 2025
C
67.5%
Roff
14.3%
Shell
10.7%
Python
5.5%
Makefile
2.0%
Binary Grep
See the codeI'm terribly annoyed by the fact that grep(1) cannot look for binary strings. I'm even more annoyed by the fact that a simple search for "binary grep" doesn't yield a tool which could do that. So I wrote one.
Feel free to modify, branch, fork, improve.
make
make install # to /user/local/bin, or
make install PREFIX=~/.local
Or, if you need it quickly,
curl -L 'https://github.com/tmbinc/bgrep/raw/main/bgrep.c' | gcc -O2 -x c -o $HOME/.local/bin/bgrep -
bgrep [-r] [-B bytes] [-A bytes] [-C bytes] <hex> [<path> [...]]
bgrep [-r] -f <pattern> [-m <mask>] [<path> [...]]
| Option | Description |
|---|---|
-B <bytes> | print <bytes> of context before each match |
-A <bytes> | print <bytes> of context after each match |
-C <bytes> | print <bytes> of context before and after a match |
-r | recurse into directories |
-f <file> | read the search pattern from a file instead of <hex> |
-m <file> | read a mask file (wildcard bytes for the pattern) |
When no path is given, bgrep reads from standard input.
Search a file for the byte sequence 0x42 0x42 0x42:
bgrep 424242 firmware.bin
Recurse through a directory:
bgrep -r 424242 ./images
BSD 2-Clause. See LICENSE.
108 followers · starred Mar 2019
650 followers · starred Jul 2016
31 followers · starred Dec 2016
162 followers · starred Feb 2025
C
67.5%
Roff
14.3%
Shell
10.7%
Python
5.5%
Makefile
2.0%