I want to traverse all subdirectories, except the "node_modules" directory.
Recent versions of GNU Grep (>= 2.5.2) provide:
--exclude-dir=dir
which excludes directories matching the pattern dir from recursive directory searches.
dir
So you can do:
grep -R --exclude-dir=node_modules 'some pattern' /path/to/search
For a bit more information regarding syntax and usage see
For older GNU Greps and POSIX Grep, use find as suggested in other answers.
find
Or just use ack (Edit: or The Silver Searcher) and be done with it!
ack
2.1m questions
2.1m answers
60 comments
57.0k users