我正在编写 grep
的脚本某些目录:
{ grep -r -i CP_Image ~/path1/;
grep -r -i CP_Image ~/path2/;
grep -r -i CP_Image ~/path3/;
grep -r -i CP_Image ~/path4/;
grep -r -i CP_Image ~/path5/; }
| mailx -s GREP email@domain.example
如何将结果限制为仅扩展 .h
和 .cpp
?
最佳答案
只需使用 --include
参数,像这样:
grep -inr --include \*.h --include \*.cpp CP_Image ~/path[12345] | mailx -s GREP email@domain.example
这应该可以满足您的需求。
从HoldOffHunger's answer获得解释下面:
grep
:命令-r
:递归-i
:忽略大小写-n
:每个输出行前面都有其在文件中的相对行号--include\*.cpp
:所有 *.cpp:C++ 文件(用\转义,以防万一你有一个文件名中带有星号的目录)./
:从当前目录开始。
关于grep - 我怎样才能递归地grep,但只能在具有某些扩展名的文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12516937/