或者在find的正则表达式中使用条件

时间:2016-05-17 15:31:16

标签: regex linux find

为什么文件存在时它什么都没有查找?

find ./ -regex '.*(jar|war)'

1 个答案:

答案 0 :(得分:2)

有关正则表达式支持的语法的信息,请参阅 man find

-regextype type
       Changes the regular expression syntax understood by  -regex  and
       -iregex tests which occur later on the command line.  Currently-
       implemented types are emacs (this is  the  default),  posix-awk,
       posix-basic, posix-egrep and posix-extended.

这有效:

$ find . -regextype egrep -regex '(.*jar)|(.*war)'

为避免使用 -regextype 将表达式更改为emacs正则表达式:

$ find . -regex '.*\(jar\|war\)'