‘--exclude-dir=dir’
Exclude directories matching the pattern dir from recursive directory searches.
|
Recent versions of GNU Grep (>= 2.5.2) provide:
‘--exclude-dir=dir’
Exclude directories matching the pattern dir from recursive directory searches.
So you can do:
grep -R --exclude-dir=node_modules 'some pattern' /path/to/search
|
# grep -Ri --exclude-dir "/var/www/directory_to_exclude" "search pattern" /var/www
Or multiple directories:# grep -Ri --exclude-dir "/var/www/directory_to_exclude" --exclude-dir "/var/www/another_directory_to_exclude" "search pattern" /var/www
Or wildcard:
# grep -Ri --exclude-dir "*.svn" "search pattern" *
Or with only exclude: # grep -Rli --exclude="*.svn*" "search string" /var/www