Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The manpage for grep describes the -I flag as follows:

-I Ignore binary files. This option is equivalent to --binary-file=without-match option.

It also says this about binary files:

--binary-files=value Controls searching and printing of binary files. Options are binary, the default: search binary files but do not print them; without-match: do not search binary files; and text: treat all files as text.

I cannot think of a scenario where I would care about matches in binary files. If such a scenario exists, surely it must be the exception rather than the norm. Why doesn't grep ignore binary files by default rather than requiring setting this flag to do so?

share|improve this question
You can set the variable GREP_OPTIONS to your preferred settings, then you don't have to use that many command line switches. – Marco Mar 28 '13 at 16:02
A note for other commands that do not support such a variable: You can set default options by defining an alias in your .(ba|z|foo)shrc': alias grep="grep -I"`. – Erik Mar 28 '13 at 19:19
This can actually be very useful. For example, I was searching for the unity version of a project, and couldn't remember which file it was kept in. I searched for the format of the version, and it came up with some binary files that matches. It turned out as it was pre-version 5, the version was only present in a binary file, so without the binary match, I might have missed it. – Svend Hansen Feb 2 at 9:17
up vote 47 down vote accepted

Not everything that grep thinks is a binary file, is actually a binary file. e.g. puppet's logs have ansi color coding in them, which makes grep think they're binary. I'd still want to search them if I'm grepping through /var/log though.

share|improve this answer
The same goes for PDF files as well. – Joseph R. Mar 28 '13 at 17:45
+ historically grep could NOT do that, so for compatibility only, default have to be all-inclusive. – Olivier Dulac Mar 28 '13 at 18:54
@OlivierDulac it makes sense, otherwise ignoring binary files should be the default. – Dagang Nov 25 '13 at 9:46

grep’s ability to search binary files is also useful when I’m compiling a program and the linker (ld) complains about some function not being found.  I can use a command like

grep function_name /lib/lib*

to find the library which contains it.  (Libraries are binary files.)

share|improve this answer
In that case, you'd rather use grep -l function_name /lib/lib* or nm -Do /lib/lib* | grep function_name or ldconfig -p | grep -o '/.*/lib.*' | xargs nm -Do | grep function_name though. – Stéphane Chazelas Jun 9 '15 at 12:11
Well, grep some_function /lib/* is shorter and usually gives correct answer - name of library I am looking for. But yes, sometimes more sophisticated approach like your ones is required too. – Daniel Frużyński Jun 9 '15 at 12:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.