+ -
当前位置:首页 → 问答吧 → cut的问题

cut的问题

时间:2011-10-12

来源:互联网

我想通过 find 查找目录中所有以 .o 结尾的文件和一个名为 main 的文件,这个 find 应该如何写?我写下边的表达式只能找到 .o 但无法找到那个 main。
find . -regex "\(.*\.\(o\)\)\|\(main\)" -ls

请各位不吝赐教。

作者: alober   发布时间: 2011-10-12

man find 可得:
引用:
-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 `b.*r3'.


所以你的main要匹配全路径, 也就是你find -type f -name main的输出,一字不差.
代码:
find . -type f -regex '.*\.o$\|.*/main$'

作者: Methuselar   发布时间: 2011-10-12

为什么不用
代码:
find -type f \( -name main -o -name '*.o' \)

作者: lilydjwg   发布时间: 2011-10-12