List files not matching a pattern?

前端 未结 9 859
我在风中等你
我在风中等你 2020-11-28 08:30

Here\'s how one might list all files matching a pattern in bash:

ls *.jar

How to list the complement of a pattern? i.e. all files not match

9条回答
  •  执念已碎
    2020-11-28 09:12

    Use egrep-style extended pattern matching.

    ls !(*.jar)
    

    This is available starting with bash-2.02-alpha1. Must first be enabled with

    shopt -s extglob
    

    As of bash-4.1-alpha there is a config option to enable this by default.

提交回复
热议问题