假设有以下目录树:
foo/
+bar/
| +VIEW/
| | +other/
| | +file.groovy
| | +file2.groovy
| | +file.txt
| +file3.groovy
+xyz/
+VIEW/
+file4.groovy
+file5.groovy
我想要只在 VIEW 或在 VIEW (即文件)下的任何目录中的groovy文件上method
。 groovy,file2.groovy和file4.groovy)。
我正在尝试使用--include=.*\/VIEW\/.*\.groovy
这样做,据我所知是任何东西然后/字符的正则表达式然后是单词VIEW然后是/字符然后是任何东西然后单词.groovy作为
但实际上并没有返回任何东西。
使用include
选项无法实现此目的吗?
答案 0 :(得分:5)
编写完成一件事并且做得好的程序。 编写程序以协同工作。
我不喜欢递归目录搜索的GNU扩展。工具find
做得更好,语法更清晰,选项更多,并没有打破理念!
$ find foo/*/VIEW -name "*.groovy" -exec grep method {} \;
答案 1 :(得分:2)
指定-path
的{{1}}选项应该有效:
find
答案 2 :(得分:1)
您不需要在include=
选项中提供目录路径,只需提供路径作为递归grep的最后一个参数。
因此你可以这样做:
grep -R 'method' --include=*.groovy foo/bar/VIEW/