我想查找所有以.c、.R或.Rd结尾的文件。我试过了
find . -iname "*.[cR]" -print它提供了所有以.c或.R结尾的文件。我如何才能另外获得.Rd文件?我知道[]只匹配一个字符,但我无法调整它以提供.Rd文件(尝试使用|或option -regex等)。
发布于 2012-12-09 01:07:43
给你=)
find -name "*.c" -o -name "*.R" -o -name "*.Rd"如果它只是你正在寻找的3种扩展类型,我建议你远离正则表达式,只使用-o (如"or")操作符来组成你的搜索。
发布于 2012-12-09 01:18:42
-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的回答,在这里,正则表达式可能不是最佳选择。
https://stackoverflow.com/questions/13779709
复制相似问题