我尝试在我的 Mac OS X 10.9 终端上执行此命令:
find / -type f -regextype posix-extended -regex "(.*A.*a.*.*)|(.*a.*A.*.*)" -exec tail -n 3 '{}' \;
但是 Bash v 3.2 的响应是:
find: -regextype: unknown primary or operator
我对终端联机帮助页进行了深入搜索:
man find
man regex
等...
但我一无所获。 Mac OS X Bash v3.2 是否应该更新?似乎选项“-regextype”不包含在“查找”中。
我该如何解决?
附注 该命令在 Ubuntu Linux 14 上完美运行。
最佳答案
对您的问题最简单的回答是,在 OS X 上您需要使用 -E
选项而不是 -regextype posix-extended
即:
find / -type f -regextype posix-extended -regex "(.*A.a..*)|(.*a.A..*)" -exec tail -n 3 '{}' \;
变成:
find -E / -type f -regex "(.*A.a..*)|(.*a.A..*)" -exec tail -n 3 '{}' \;
除了提示的 -exec tail
命令外,上面的命令适用于我的 10.10 安装。
这实际上包含在手册页的第一个条目中:
The options are as follows:
-E Interpret regular expressions followed by -regex and -iregex primaries as extended (modern) regular expressions rather than basic
regular expressions (BRE's). The re_format(7) manual page fully describes both formats.
关于regex - 在 Mac OS X 上使用命令 find 扩展 POSIX 实用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25094004/