Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有-regex选项的Linux`find`命令无法按预期工作_Regex_Linux_Bash_Find - Fatal编程技术网

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

带有-regex选项的Linux`find`命令无法按预期工作,regex,linux,bash,find,Regex,Linux,Bash,Find,我在当前目录中有一个foo文件。然后运行以下命令: 找到-正则表达式“foo”找不到任何内容 找到-正则表达式“foo.*”找不到任何内容 找到-regex'.*foo'查找该文件 我希望这两条命令中的任何一条都会产生积极的结果 手册中的“查找”命令版本为4.4.2: -regex pattern File name matches regular expression pattern. This is a match on the who

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

找到-正则表达式“foo”找不到任何内容 找到-正则表达式“foo.*”找不到任何内容 找到-regex'.*foo'查找该文件 我希望这两条命令中的任何一条都会产生积极的结果

手册中的“查找”命令版本为4.4.2

   -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.
重要的一点是:这是整个路径上的匹配,而不是搜索

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

./foo
实际上,find尝试以与-name开关不同的方式匹配字符串./foo,因此,如果文件foo没有扩展名,则第三个模式-regex'.*foo'必须工作

尝试使用:

``find . -regex '.*foo.*'``

然后报告输出。

第二种情况下正确的正则表达式是“\./foo.*”吗?@SergeyPauk是,第一种情况下正确的正则表达式是“\./foo”:-