随笔 - 1682  文章 - 617 评论 - 436 trackbacks - 0

‘--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
posted on 2013-10-08 21:57 一天不进步,就是退步 阅读(...) 评论(...) 编辑 收藏