第一个没有管道的示例返回空。
find /tmp/txz/httperf/httperf-20210403git/ -regextype posix-egrep -regex [A-Z][A-Z]$
第二个返回我想要的,所有带有大写字母的文件,为什么find命令不返回任何内容?
find /tmp/txz/httperf/httperf-20210403git/ |egrep [A-Z][A-Z]$
/tmp/txz/httperf/httperf-20210403git/.git/refs/remotes/origin/HEAD
/tmp/txz/httperf/httperf-20210403git/.git/logs/refs/remotes/origin/HEAD
/tmp/txz/httperf/httperf-20210403git/.git/logs/HEAD
/tmp/txz/httperf/httperf-20210403git/.git/HEAD
/tmp/txz/httperf/httperf-20210403git/NEWS
/tmp/txz/httperf/httperf-20210403git/COPYRIGHT
/tmp/txz/httperf/httperf-20210403git/AUTHORS
/tmp/txz/httperf/httperf-20210403git/TODO
/tmp/txz/httperf/httperf-20210403git/src/lib/README
我也尝试过 posix-extended 和 posix-basic 对于正则表达式类型,但返回空。
答案1
由于 POSIXfind
没有指定-regex
,我假设是 GNU find
。
测试:
-regex expr
测试:-iregex expr
如果整个文件名与正则表达式匹配,则为 Trueexpr
。这是整个路径的匹配,而不是搜索。[…]
(来源,强调我的)
你应该使用-regex '.*[A-Z][A-Z]'
.请注意,该表达式是单引号的,以防止 shell 进行扩展。