Is it possible to both search recursively and with a given file pattern?
I am trying to do the equivalent of
find ./ -name "*.[c|h]" -exec grep -Hn PATTERN {} \;
Obviously you can use grep's -r flag, but when I specify a filename pattern such as:
grep -Hn -r PATTERN *.c
It only looks for *.c files in the current directory, not recursively.
I found this, but it does not talk about specifying filenames: Recursive grep vs find / -type f -exec grep {} \; Which is more efficient/faster?
grep
also has that switch though patterns are matched to the full path as opposed to base name in GNU – don_crissti Jan 12 '17 at 17:54grep
selects directories for the-r
case: even in GNU grep, older versions require an explicit starting directory argument e.g.grep -Hrn --include="*.[ch]" PATTERN .
– steeldriver Jan 12 '17 at 18:27