Is there a way to grep with a constrained file type?

Solution 1:

POSIX grep doesn't have such options, but coreutils grep does.

grep -r --include='*.xml' -l foobar .

should do it.

FreeBSD grep (and OS X) appear to have the same thing, Solaris & AIX lack them AFAICT.

Solution 2:

You could also do:

find . -name "*.xml" -exec grep -l "foobar" {} \;