小编sti*_*oob的帖子

find 中的“regex”和“name”指令

命令-name选项需要什么样的正则表达式语法find?我的印象是它与 for 相同,-regex但似乎并非如此。

$ mkdir test && cd test
$ touch .sw.
$ touch .swp
$ touch .abc.swo
$ touch notswap.py
$ find . -name "*sw." -type f
./.sw.
$ find . -name "*sw*" -type f
./notswap.py
./.sw.
./.swp
./.abc.swo
$ find . -regex ".*sw." -type f
./.sw.
./.swp
./.abc.swo
Run Code Online (Sandbox Code Playgroud)

FWIW,我知道-regex匹配整个路径并且-name只匹配文件名的基数。我希望很明显,这不是这里的问题。作为一个更具体的问题,如何使用该选项匹配以.swxwherex可以是任何字符结尾的所有文件-name

元信息:

$ find --version
find (GNU findutils) 4.5.11
...
$ echo $0
bash
Run Code Online (Sandbox Code Playgroud)

find regular-expression

3
推荐指数
1
解决办法
406
查看次数

标签 统计

find ×1

regular-expression ×1