I am trying to use grep to find some tex files containing the pattern ->-
:
grep -R -- "->-" *.tex
But this doesn't work. If I do:
grep -R -- "->-"
instead, it works, but is really slow and gives me clearly not only tex files but also matches lots of other file (for example binary files).
What would be the fastest way to do this search?
Best Answer
The problem is that
-R
tellsgrep
to recursively search through all files in the directory. So, you can't combine it with a specific group of files. Therefore, you can either usefind
as suggested by @KM., or shell globbing:The
shopt
command activates bash's globstar feature:You then give
**/*.tex
as a pattern and that will match all.tex
files in the current directory and any subdirectories.If you're using
zsh
, there's no need for theshopt
(which is a bash feature anyway) sincezsh
can do this by default.