我常用的grep

find ./ -regex '.*\.\(cc\|h\|cpp\)'|xargs grep -P --color=auto -R -n '\bReAddAll'

-P  perl模式正则,无需字符转义

--color=auto  自动着色

-n  显示行号

 

grep -R "wangkangluo"  /var/www/html   //所有目录文件下查找字符串

 

比如,我想搜源码目录src下,包含“niuc”的所有ec文件

find ./src -name '*.ec' -exec grep -i niuc {} /; -print

 

在特定文件中grep某关键字,除了使用find 命令加exec选项之外,其实还有更简单的方法:

grep -R --include="*.cpp" key dir

上述命令的含义:

在dir目录下递归查找所有.cpp文件中的关键字key

 

是不是更简单呢?

posted @ 2012-02-05 14:23  wangkangluo1  阅读(383)  评论(0编辑  收藏  举报