bash wildcard n digits

前端 未结 4 1633
难免孤独
难免孤独 2021-01-05 11:21

So I\'ve got the following files in the tmp directory:

 file.0
 file.1
 file.t9
 file.22
 file.4444

if I wanted to list only the files that

4条回答
  •  抹茶落季
    2021-01-05 12:23

    At least in bash 4, when the extglob shell option is enabled:

    shopt -s extglob
    ls /tmp/file.+([0-9])
    

    The pattern +([0-9]) there matches one or more digits.

    You can read more about this in the Pattern Matching section of man bash.

    UPDATE

    Actually, as @chepner pointed out, since extglob was introduced in version 2.02, this should work in pretty much every bash you come across today, unless you pulled your distro out of a rock or something.

提交回复
热议问题