Regular Expressions for file name matching

前端 未结 6 1234
自闭症患者
自闭症患者 2020-12-30 06:18

In Bash, how does one match a regular expression with multiple criteria against a file name? For example, I\'d like to match against all the files with .txt or .log endings.

6条回答
  •  执念已碎
    2020-12-30 06:39

    You can also do this:

    shopt -s extglob
    for file in *.+(log|txt)
    

    which could be easily extended to more alternatives:

    for file in *.+(log|txt|mp3|gif|foo)
    

提交回复
热议问题