>  Q&A  >  본문

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

PHP中文网PHP中文网2716일 전537

모든 응답(2)나는 대답할 것이다

  • 大家讲道理

    大家讲道理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.
    

    这个参数会影响,-regex [pattern]的匹配行为,类似使用不同的方言来解析正则表达式。
    经过我的实验,我觉得这么写

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

    ./auto..../是不能省略的,find的正则匹配不能够只匹配部分,要匹配完全(理解)。

    ==update==
    如果前面的路径很长,可以这样子匹配

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

    회신하다
    0
  • 伊谢尔伦

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

    如果使用find * 然后再配合egrep,lz你怎么看?

    회신하다
    0
  • 취소회신하다