'grep -R string * .txt', even if top dir does not have a .txt file

I don’t remember when the command line switch with the recursive search -R was introduced in grep , but now I can not imagine life without it.

The only problem is that if any directory in the recursion does not match the wildcard file name, grep -R will stop and will not be able to report directories and files that create positive search results.

For instance:

grep -R skeleton_app *.xml 

Report only

 AndroidManifest.xml: <application android:label="@string/skeleton_app"> 

While:

  grep -R skeleton_app * 

Reports all:

 AndroidManifest.xml: <application android:label="@string/skeleton_app"> Binary file bin/classes.dex matches Binary file bin/com/example/android/skeletonapp/R$string.class matches gen/com/example/android/skeletonapp/R.java: public static final int skeleton_app=0x7f050000; res/values/strings.xml: <string name="skeleton_app">Understanding Intents</string> 

My question is: is there a way to tell ' grep -R ' not to dwell on file name mismatch?

+4
source share
2 answers

Try:

 grep -R --include '*.xml' skeleton_app . 
+13
source

Use find in addition to grep.

 $ find ./ -name "*.txp" -exec grep "string" '{}' \; -print 
0
source

Source: https://habr.com/ru/post/946534/


All Articles