带有 -regex 选项的 Linux“find”命令无法按预期工作

Ser*_*auk 3 regex linux bash find

foo我在当前目录中有一个文件。然后我运行以下命令:

  1. find . -regex 'foo'什么也没找到
  2. find . -regex 'foo.*'什么也没找到
  3. find . -regex '.*foo'找到文件

我希望这些命令中的任何一个都会产生积极的结果。

find命令版本是4.4.2

cad*_*ian 5

从手册:

   -regex pattern
          File name matches regular expression pattern.  This is  a  match
          on  the  whole path, not a search.  For example, to match a file
          named `./fubar3', you can use the regular expression `.*bar.' or
          `.*b.*3',  but  not `f.*r3'.  The regular expressions understood
          by find are by default Emacs Regular Expressions, but  this  can
          be changed with the -regextype option.
Run Code Online (Sandbox Code Playgroud)

重要的部分是:这是整个路径上的匹配,而不是搜索

因此只有第三个正则表达式会产生结果:

./foo
Run Code Online (Sandbox Code Playgroud)