bash wildcard n digits

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

    Another variant for filtering files of a specific extension is to use the find command with a set of predicates:

    find tmp/ -type f -iregex '^.*\.[0-9]+$'
    

    The -type predicate matches only files and the -iregex matches names that end with one or more digits - ignoring case of the name. If you want to filter files that begin with file you would use the following instead:

    find tmp/ -type f -iregex '^.*/file\.[0-9]+$'
    

    And finally, if you don't want the whole path displayed for each resulting file, use the following:

    find tmp/ -type f -iregex '^.*/file\.[0-9]+$' -printf "%f\n"
    

提交回复
热议问题