使用 find 命令查找特定文件扩展名
我想找到给定根目录中文件名包含任意扩展名的任何文件。 我看到了这个帖子: 如何删除文件前面带有特定后缀的所有文件扩展
根据该信息,我尝试了以下操作:
find . -iregex ".*\.\(wav\|aif\|wave\|aiff\)"
这似乎应该工作,但我没有将任何结果打印到终端窗口。
有人可以提供建议吗?我使用的是 OSX 10.7
谢谢, 杰姆
I would like to find any files within a given root that contain arbitrary extensions in the filename.
I saw this post:
How to delete all files with certain suffix before file extension
Based on that information, I tried this:
find . -iregex ".*\.\(wav\|aif\|wave\|aiff\)"
This seems like it should work, but I don't get any results printed to the terminal window.
Can anyone offer advice? I'm on OSX 10.7
Thanks,
jml
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在查找:
您缺少转义符、
\
、or 上的字符、|
、运算符You are looking for:
You were missing escape,
\
, characters on the or,|
, operators这是一个
emacs
风格的正则表达式吗?如果没有,请尝试使用
-regextype
。从 Linux 上的find
手册页(过时):-regextype type
更改稍后在命令行上发生的
-regex
和-iregex
测试所理解的正则表达式语法。当前实现的类型有emacs
(这是默认值)、posix-awk
、posix-basic
、posix-egrep
code> 和 posix-extend。在 MacOS X 上,
find
的手册页显示:一些实验表明:
在我的文件夹中找到了一大堆 PDF 文件,但这些变体都找不到任何内容:
因此,人们被迫假设 MacOS X (BSD) 支持的正则表达式
find 不包括已识别字符之间的交替(括号和竖线)。遗憾的是:
man 7 re_format
暗示它可能,但事实并非如此。 MacOS X (BSD) 似乎不支持-regextype
选项。因此,最简单的方法可能是安装 GNU
find
,或者对 N 个不同的文件扩展名进行 N 次单独的搜索,或者对一般文件进行一次搜索并使用egrep '\.(aff |wave?|aiff)$'
来捕获您感兴趣的文件。这假设您不在文件名中使用换行符(空格等可以,但换行符不行)。Is that an
emacs
style regex?If not, try using
-regextype
. From thefind
man page on Linux (archaic):-regextype type
Changes the regular expression syntax understood by
-regex
and-iregex
tests which occur later on the command line. Currently-implemented types areemacs
(this is the default),posix-awk
,posix-basic
,posix-egrep
andposix-extended
.On MacOS X, the manual page for
find
says:Some experimentation shows that:
finds a whole lot of PDF files in my folder full of them, but none of these variants find anything:
Consequently, one is forced to assume that the regexes supported by MacOS X (BSD)
find
do not include alternation (parentheses and pipes) amongst the recognized characters. 'Tis a pity:man 7 re_format
implies it might, but it doesn't. The-regextype
option is not supported on MacOS X (BSD), it seems.So, it may be simplest to install GNU
find
, or to do N separate searches for the N different file extensions, or do one search for files in general and useegrep '\.(aff|wave?|aiff)$'
to catch the files you're interested in. That rather assumes you don't use newlines in file names (spaces etc are OK, but newlines are not).