How to match files *.R and *Rd with find utility?

后端 未结 2 1096
温柔的废话
温柔的废话 2021-01-17 13:13

I would like to find all files that end with .c, .R, or .Rd. I tried

find . -iname \"*.[cR]\" -print
<
2条回答
  •  不知归路
    2021-01-17 14:00

    A suitable use of -regex would be:

    find -regex '.*\.\(R\|Rd\|c\)'
    

    If you want to use regular expressions you need to keep in mind that these apply to the whole path, not only to the filename:

       -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.
    

    I agree with sampson-chen's answer, that regexes are probably not the best choice here.

提交回复
热议问题