Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
1  
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
1  
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

1 Answer 1

up vote 15 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
1  
The same goes for PDF files as well. –  Joseph R. Mar 28 '13 at 17:45
2  
+ 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. –  Todd Nov 25 '13 at 9:46

Your Answer

 
discard

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.