How can I exclude directories from grep -R?

来源:互联网 发布:淘宝好评晒图怎么删掉 编辑:程序博客网 时间:2024/05/01 06:44
‘--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 Exclude Directory

# 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
0 0