我想查找以 、 或 . 结尾的.c所有.R文件.Rd。我试过
find . -iname "*.[cR]" -print
.c它给出了所有以or结尾的文件.R。我怎样才能另外获取.Rd文件?我知道[]只匹配一个字符,但我无法调整它以提供.Rd文件(尝试使用|或选项-regex等)
给你=)
find -name "*.c" -o -name "*.R" -o -name "*.Rd"
如果它只是您正在寻找的 3 种扩展类型,我建议您远离正则表达式,而只使用-o(如“或”)运算符来组成您的搜索。
一个合适的用途-regex是:
find -regex '.*\.\(R\|Rd\|c\)'
如果你想使用正则表达式,你需要记住这些适用于整个路径,而不仅仅是文件名:
-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 `f.*r3'. The regular expressions understood
by find are by default Emacs Regular Expressions, but this can
be changed with the -regextype option.
我同意 sampson-chen 的回答,正则表达式可能不是这里的最佳选择。