Recursive text search with grep and file patterns

My version of GNU Grep has a switch for this:

grep -R --include='*.txt' $Pattern

Described as follows:

--include=GLOB

Search only files whose base name matches GLOB (using wildcard matching as described under --exclude).


If you have a large number of files it would be useful to incorporate xargs into the command to avoid an 'Argument list too long' error.

find . -name '*.txt' -print | xargs grep <pattern>

you might be able to make use of your zsh's EXTENDED_GLOB option (docs)

grep <pattern> **/*.txt