相关疑难解决方法(0)

查找和正则表达式

这个 find 表达式我做错了什么?

; touch ook ooks
; find . -name 'ook' -or -name 'ooks' -type f
./ook
./ooks
; find . -name 'ook[s]?' -type f      
[returns nothing]
; echo $?
0
Run Code Online (Sandbox Code Playgroud)

find regular-expression

4
推荐指数
2
解决办法
5896
查看次数

用 GNU find 理解 -regex

背景

我有我认为应该是一个简单的案例。我想找到名称中带有“cisco”的所有文件,并对这些文件进行处理(通过xargs)。

查找文件 ls

在我使用xargs之前,第一步是列出所有相关文件。列出文件很容易ls | grep cisco...

[mpenning@Bucksnort post]$ ls | grep cisco
cisco-asa-double-nat.rst
cisco-asa-packet-capture.rst
cisco-eem-tcl.rst
cisco-ip-sla-tracking.rst
cisco_autonomous_to_lwap.rst
[mpenning@Bucksnort post]$
Run Code Online (Sandbox Code Playgroud)

查找文件 find

尽管在这种特定情况下可能不需要它,但是当管道进入xargs时,通常认为find更安全。但是,当我使用.find -regex

[mpenning@Bucksnort post]$ find -regextype grep -regex ".*/cisco*" -print
[mpenning@Bucksnort post]$
Run Code Online (Sandbox Code Playgroud)

但是,我知道我可以找到这些文件...

[mpenning@Bucksnort post]$ find | grep cisco
./cisco-eem-tcl.rst
./parsing-cisco-output-w-textfsm.rst
./cisco_autonomous_to_lwap.rst
./cisco-ip-sla-tracking.rst
./cisco-asa-double-nat.rst
./cisco-asa-packet-capture.rst
[mpenning@Bucksnort post]$
Run Code Online (Sandbox Code Playgroud)

问题

我意识到find -regex必须匹配返回的完整路径,但为什么不能find -regextype grep -regex ".*/cisco*" -print在上面工作?不应该.*/cisco*匹配路径吗?


笔记 …

find xargs regular-expression

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

标签 统计

find ×2

regular-expression ×2

xargs ×1