开发者

How to grep a String in all the java files in subdirectories?

I w开发者_Go百科ant to use grep to find the lines contain String in all java files under current directory.

I tried:

grep -r "String" **/*.java

But it doesn't work:

grep : **/*.java:  no such file or directory

How to write it?


UPDATE

I'm on windows, using the grep provided by unxUtils, which doesn't support --include parameter. Is there any other way?


Use recursive grep:

grep -r "String" --include=*.java .


I guess the unxUtils provide the find utility. So you could try to do:

find . -name "*.java" -exec grep "String" {} \;

or

find . -name "*.java" -exec grep "String" {} \+

The first version will execute one grep command for each file found. The latter version will only execute as many grep commands as necessary but not every find version supports the + argument.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜