One can use grep "mystring" myfile.ext
to find the lines in myfile.ext
containing mystring
. One could also use grep "mystring" *.ext
to find mystring
in all files with extension ext
. Similarly, one could use grep "mystring" /directory
to search for mystring
in all files in the directory. What if one wants to search for mystring
in all *.ext
files in a certain path /directory
? Most posts online would suggest something along the line of
<pre class="src src-sh">find /directory -type -f -name <span style="color: #ffa07a;">"*.ext"</span> | xargs grep <span style="color: #ffa07a;">"mystring"</span>
However, the comments of this post shows how one could do it with grep
:
<pre class="src src-sh">grep -r --include=*.ext <span style="color: #ffa07a;">"mystring"</span> /directory