3

I find single exclude extension like

grep --exclude "*.js" "a" *

How do I write multiple exclude masks?

I have tried the code below, but it doesn't work:

grep -r --exclude=*.\{html,htm,js} "li" *

grep -R -E '(\.js|rb)' "create" * 

3 Answers 3

15

You should escape the asterisk, not the curly brace. Your command should look like this:

grep -r --exclude=\*.{html,htm,js} "li" *
3

man grep *scroll scroll scroll*

 --exclude=GLOB
          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.

Look up "shell globbing" for more info

Example:

$ grep -r  --exclude=\*.{png,jpg} a .
./moo.txt:a
./moo.htm:a
./hai:a

$ ls
hai  hai.png  moo.htm  moo.txt

Similar question

0

I was looking for exact same thing, but I want to use -v instead, I found the solution here

grep -v -e html -e htm -e js

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .