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


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


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


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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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