bash wildcard n digits

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

    Another simple solution to just prevent seeing (ie hide) "ugly errors" is to redirect standard error to /dev/null by appending 2> /dev/null. In your example:

    ls tmp/file.{[0-9],[0-9][0-9],[0-9][0-9][0-9],[0-9][0-9][0-9][0-9]} 2> /dev/null
    

    This would give you the results you want and hide any errors. Works with any linux command or executable that sends output to stdout and errors to stderr. Note that this does not affect the command return status ($?), it just suppresses errors.

提交回复
热议问题