这个 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) 我有我认为应该是一个简单的案例。我想找到名称中带有“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*
匹配路径吗?
笔记 …