Home  >  Q&A  >  body text

正则表达式 - Linux上,如何让find命令支持正则查找?

PHP中文网PHP中文网2716 days ago536

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 15:57:00

    -regextype type
                  Changes the regular expression syntax understood by -regex and -iregex tests which occur later on the command line.  Currently-implemented types are emacs (this is the default),  posix-awk,  posix-basic,  posix-egrep  and  posix-
                  extended.
    

    This parameter will affect the matching behavior of -regex [pattern], similar to using different dialects to parse regular expressions.
    After my experiment, I feel like writing this

    find . -regextype posix-extended -regex './autojump.(bash|zsh|sh)'
    或者
    find . -regextype posix-extended -regex './autojump.(ba|z)?sh'
    
    The regular matching of

    ./auto..../是不能省略的,find cannot only match part of it, but must match completely (understand).

    ==update==
    If the previous path is very long, you can match it like this

    find . -regextype posix-extended -regex '.*autojump.(ba|z)?sh'

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 15:57:00

    If you use find * and then use egrep, what do you think?

    reply
    0
  • Cancelreply