![](/img/trans.png)
[英]grep a keyword in all .h and .c files under current directory but exclude two directories
[英]grep exclude-dir in current directory or subdirectories
我正在尝试将我的GREP_OPTIONS
设置为始终排除某些目录(例如target/classes
)。 我专门试图使它适用于递归gr。 当当前目录包含target/classes
,使用--exclude-dir=target/classes
效果很好,但是当我位于父目录中时,情况并非如此。 我当前的解决方案要求我同时设置--exclude-dir=target/classes
和--exclude-dir=*/target/classes
。 我正在寻找一个更直接的解决方案,我认为它将涉及一个正则表达式。 我已经尝试了--exclude-dir=(*/)?target/classes
和其他排列方式,但是我无法使其正常工作。
是的,我相信可以使用其他工具(例如,find,awk等)来完成此操作,但是我真的很想将其限制在GREP_OPTIONS
解决方案中(如果可能)。
这是一个经过测试的工作示例,请谨慎使用语法,不要输入错误:
root/dspace# grep -r --exclude-dir={log,assetstore} "creativecommons.org"
在上面的grep中,当前目录“ dspace”中的文本“ creativecommons.org”不包括目录{log,assetstore}。
完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.