December 09, 2008

recursive 的對 .h 和 .cpp 作 grep

一直都不會,通常都是用 grep -r PATTERN * | grep cpp :X,今天被問所以認真的查了一下...

  1. find DIRECTORY -name '*h' -o -name '*cpp' | xargs grep PATTERN
  2. grep -r --include '*.h' --include '*cpp' PATTERN * (或DIRECTORY)
以後就會了 =_=

Edit: 2009/4/20

alias mygrep 'grep -n -r --include "*.h" --include "*.cpp" \!* *'
之後打 mygrep PATTERN 就好了 =_=

No comments: