$ find --version
find (GNU findutils) 4.6.0
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION
FTS(FTS_CWDFD) CBO(level=2)
$ find --version
find (GNU findutils) 4.4.2
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Built using GNU gnulib version e5573b1bad88bfabcda181b9e0125fb0c52b7d3b
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS() CBO(level=0)
susam@nifty:~/so$
susam@nifty:~/so$ find . -regextype foo -regex ".*/[a-f0-9\-]\{36\}\.jpg"
find: Unknown regular expression type `foo'; valid types are `findutils-default', `awk', `egrep', `ed', `emacs', `gnu-awk', `grep', `posix-awk', `posix-basic', `posix-egrep', `posix-extended', `posix-minimal-basic', `sed'.
7 回答
简单的方法 - 你可以在开头指定 . *因为find匹配整个路径 .
找到版本
从其他答案来看,似乎这可能是找错了 .
但是你可以这样做:
find . * | grep -P "[a-f0-9\-]{36}\.jpg"
您可能需要稍微调整一下grep并根据您的需要使用不同的选项,但它可以正常工作 .
-regex
find表达式与 whole name 匹配,包括当前目录的相对路径 . 对于find .
,这始终以./
开头,然后是任何目录 .此外,这些是
emacs
正则表达式,其具有除通常的egrep正则表达式之外的其他转义规则 .如果这些都直接在当前目录中,那么
应该管用 . (我'm not really sure - I can' t计算重复在这里工作 . )你可以通过
-regextype posix-egrep
切换到egrep表达式:(请注意,这里所说的一切都是针对GNU查找的,我对BSD一无所知,这也是Mac上的默认设置 . )
请注意,您需要在开头指定
.*/
,因为find
与整个路径匹配 .例:
我的发现版本:
尝试使用单引号(')来避免shell转义为字符串 . 请记住,表达式需要匹配整个路径,即需要看起来像:
除此之外,似乎我的find(GNU 4.4.2)只知道基本的正则表达式,特别是{36}语法 . 我想你将不得不做它 .
在使用正则表达式应用查找指令时,应使用绝对目录路径 . 在你的例子中,
应改成
在大多数Linux系统中,正则表达式中的某些规则无法被该系统识别,因此您必须明确指出-regexty
on Mac (BSD find) :与接受的答案相同,需要
.*/
前缀来匹配完整路径:man find
说-E
使用扩展的正则表达式支持