bash wildcard n digits

前端 未结 4 1681
难免孤独
难免孤独 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:04

    You can use ls just to list all the files then filter the output of that through grep:

    ls -1 | grep -E '\.[0-9]+$'
    

    as per the following test:

    pax> printf 'file.0\nfile.1\nfile.t9\nfile.22\nfile.4444\n' | grep -E '\.[0-9]+$'
    file.0
    file.1
    file.22
    file.4444
    

    The -E gives you extended regular expressions so that the + modifier works. If that's not available to you, you can use the \.[0-9][0-9]*$ regex instead.

提交回复
热议问题