Arp*_*ith 6 regex bash file-extension
我目前正在使用
find . -name '*.[cCHh][cC]' -exec grep -nHr "$1" {} ; \
find . -name '*.[cCHh]' -exec grep -nHr "$1" {} ;
Run Code Online (Sandbox Code Playgroud)
在所有子目录中列出的以.c,.C,.h,.H,.cc和.CC结尾的文件中搜索字符串.但由于这包括两个命令,因此效率低下.
如何使用单个正则表达式模式查找.c,.C,.h,.H,.cc和.CC文件?
我在Linux机器上使用bash.
rid*_*rid 16
您可以使用布尔OR参数:
find . -name '*.[ch]' -o -name '*.[CH]' -o -name '*.cc' -o -name '*.CC'
Run Code Online (Sandbox Code Playgroud)
上面找到以下结尾的文件:
.c
,.h
或.C
,.H
或.cc
要么.CC
.dou*_*own 11
这应该工作
乱
find . -iregex '.*\.\(c\|cc\|h\)' -exec grep -nHr "$1" {} +
Run Code Online (Sandbox Code Playgroud)
-iregex
对于不区分大小写的正则表达式模式.
(c|cc|h)
(讨厌的转义未显示)匹配c,cc或h扩展名
清洁
find -regextype "posix-extended" -iregex '.*\.(c|cc|h)' -exec grep -nHr "$1" {} +
Run Code Online (Sandbox Code Playgroud)
这也会找到.Cc和.cC扩展名.你被警告了.