mardi 3 février 2015

How can I recursively grep through several directories at once?


I use grep -r all the time to find occurrences of a string within files in a given directory:



$ grep -r "string" app/assets/javascripts
> app/assets/javascripts/my_file.js: this line contains my string

But what if I want to recursively search through more than one subdirectory of my current directory? The only way I can think of is to run grep twice:



$ grep -r "string" app/assets/javascripts
> app/assets/javascripts/my_file.js: this line contains "string"
$ grep -r "string" spec/javascripts
> app/assets/javascripts/my_file.js: "string" appears here, too.

How can I combine the above two grep commans into a single line? I don't want to search through every single file in ., and --exclude-dir isn't practical because there are too many other directories under . for me to explicitly exclude them all.


Is this possible?



Aucun commentaire:

Enregistrer un commentaire