gab*_*bor 52 linux grep command-line
我经常使用递归 grep 来查找具有特定内容的源文件。
grep -Rni "myfunc" .
Run Code Online (Sandbox Code Playgroud)
在大型代码库上,这可能会变慢,所以我使用 --incldue 来限制/白名单扩展。
grep -Rni --include=*.java "myfunc" .
Run Code Online (Sandbox Code Playgroud)
但是,排除(修剪)整个子目录会更有效,我在想:
grep -Rni --exclude=/.svn/ "myfunc" .
Run Code Online (Sandbox Code Playgroud)
但是 --exclude 只支持像上面的 *.java 这样的文件模式。如何排除目录?
小智 67
grep -r --exclude-dir=dev --exclude-dir=sys --exclude-dir=proc PATTERN data
Run Code Online (Sandbox Code Playgroud)
来源:https : //stackoverflow.com/questions/2799246/grep-exclusive-a-specific-folder-using
您可以使用 find 代替:
find . -not -path "*/.svn*" -not -type d -exec grep -ni "myfunc" {} \; -print
Run Code Online (Sandbox Code Playgroud)
好的,这就有点倒退了,你先得到 grep 结果,然后是路径。也许其他人有更好的答案?