I'm a linux newbie. I need to search for a string "teststring" in all *.java files coming under /home/user1/ (including subfolders). How can I do it in linux via shell command.
Asked
Active
Viewed 7,589 times
5 Answers
27
The easiest way is to use GNU grep's features:
grep -r --include '*.java' teststring /home/user1
If you're ever on another unix variant that doesn't have GNU grep, here's a portable way:
find /home/user1 -name '*.java' -exec grep teststring {} +
Gilles 'SO- stop being evil'
- 72,151
3
Found it. Posting it as it might help someone.
find /home/user01 -name *.java | xargs grep "teststring"
Please correct if there is any better way.
softwarematter
- 3,989