linuxshellgrepcommand

how to exclude multiple pattern using grep


I want to exclude both "*log*" and ./tags from grep.

What i do is:

grep -rI "PatternToSearch" ./path --exclude="*log*" 

or this:

grep -rI "PatternToSearch" ./path --exclude="tags"

is it possible to merge both exclude patterns in one grep?


Solution

  • Try below:

     grep -rI "PatternToSearch" ./path --exclude={*log*,tags}
    

    Just use "," to separate patterns.

    Seems duplicated with how do I use the grep --include option for multiple file types?