Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

right now i am using something like this:

find . -name "*.xml" | xargs grep -l "foobar"

it works, but i was wondering if grep has this functionality built in?

share|improve this question
up vote 7 down vote accepted

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.

share|improve this answer

You could also do:

find . -name "*.xml" -exec grep -l "foobar" {} \;
share|improve this answer
yeah i used that originally but then switched to xargs because its faster – numan May 19 '12 at 21:05

You can use ack where that command would be

ack --xml -l foobar

Note that ack's filetypes mean that it doesn't just consider *.xml files. Any file with the extension .xml, .dtd, .xsl, .xslt, or .ent will be selected for searching under the --xml flag. See ack --help-types for a list of types and extensions.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.