How does egrep under Linux ignore specific end files/specific folders/binary files?

  linux, question

Describe the problem

There are three requirements (see title), and these are common.
However, I searched the man document and followed its instructions, but I always felt that my posture was wrong (not in line with the expected results)

Then Google did some research, and the results were nothing more than man documents.
So my question can be translated into: how do you read the part about exclude in the document?

According to my own understanding, it can be summarized as follows:

  1. Use shell wildcard characters

  2. -exclude –exclude-from, –exclude-dir-dir is for files and folders respectively.-exclude seems to be a big option

  3. For binary files-IBut how does grep know which are binary files? (Should there be some configuration option? )

For example, in these cases, the commands I have constructed are as follows

  1. Ignore.pycFile--exclude-from="*.pyc"

  2. Ignore.svnDirectory--exclude-dir="\.svn"

  3. Ignore binary files,-I(I really don’t understand this option)

Context environment

  1. Linux Ubuntu16

  2. GNU grep 2.6.3

  3. My alias:alias grep='egrep --color=auto'

Commands I Construct at Work:grep -r --exclude-dir="\.svn" 'KeyValue\b' ./


  1. man grep

  2. The. svn directory is best, the. git directory can also be, or other

  3. Try some of grep’s exclude options.

  4. View expected results

Related codes

Excerpt the search results on exclude from grep’s man document

 Skip  files  whose  base  name  matches GLOB (using wildcard matching).  A file-name glob can use *, ?  , and [...]  as wildcards, and \ to quote a wildcard or
 backslash character literally.
 Skip files whose base name matches any of the file-name globs read from FILE (using wildcard matching as described under --exclude).
 Exclude directories matching the pattern DIR from recursive searches.

Error message

The order I have constructed isgrep -r --exclude-dir="\.svn" 'KeyValue\b' ./
The error message is: files in. svn will still be searched

Related screenshots

What methods have been tried but still have not been solved (with relevant links attached)

The result is very easy to find, but I don’t know why my result is a little different.

  1. grep ignore spcific directory

  2. grep exclude binary file

  3. grep exclude some file

  4. grep exclude pyc file

Problem simplification

With pipes, like this?

find -type f (-not -name '*ext') -and (-not -type d -name 'dir') | xargs -n1 -I{} grep --exclude=GLOB 'search_str' {}