Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am trying to figure out how to search for "_iterator_tag" string in all sub directories recursively and in files with extensions .cpp, .h, .hpp, .cxx, .inl for now all I can do is search each of these file types separately as below grep -R "_iterator_tag" --include '*.cpp' Is there a quicker way to search all of these file types together? Thank you

share|improve this question

4 Answers 4

I define the following aliases in my .bashrc

ffg() { eval find $1 | xargs -n 1 grep -nH $2 2>/dev/null ; }
fc() { ffg "-name \*.c -o -name \*.cpp" "$*"; }
fh() { ffg "-name \*.h -o -name \*.hpp" $* ; }
fch() { ffg "-name \*.c -o -name \*.cpp -o -name \*.h -o -name \*.hpp" $* ; }

So I'd typically do:

cd <root subdir>    
fch _iterator_tag

Of course you'd need a different set of file types.

share|improve this answer

You can specify multiple instances of --include on the command line (they are "or"ed together).

Edit: Specifically

 grep -r --include '*.cpp' --include '*.h' --include '*.hpp' --include '*.cxx' --include '*.inl' "_iterator_tag" /some/path
share|improve this answer


find /some/path -name \( '*.cpp' -o -name '*.h' -o -name '*.hpp' -o -name '*.cxx' -o -name '*.ini' \) | xargs grep "_iterator_tag"
share|improve this answer

use ack. It's great for searching source code (and not looking in images, or RCS artifacts, like .svn directories)

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.