43
8
When I want to perform a recursive grep search in the current directory, I usually do:
grep -ir "string" .
But that command searches inside all kinds of files, including binary files (pictures, audio, video, etc...) which results in a very slow search process.
If I do this, for example, it doesn't work:
grep -ir "string" *.php
It doesn't work because there are no PHP files inside the current directory, but inside some of the subdirectories in the current directory, and the subdirectories' names don't end with ".php" so grep doesn't look inside them.
So, how can I do a recursive search from the current directory but also specifying filename wildcards? (i.e: only search in files which end in a specific extension)
I had to replace the period at the end and use:
grep -ir "string" --include="*.php" *
– Stuart – 2015-07-21T17:41:52.013I thought period was just the end of the line! I did not use or need. – boardtc – 2018-11-05T14:59:52.310
1Ok, it seems my version of grep was old, because it didn't have that option (no wonder why I couldn't figure out how to do this!). I got the message: "grep: unrecognized option `--include=*.php'". But I just upgraded to a newer one and now it works. Thank you! – OMA – 2014-05-23T09:03:28.097