How to suppress error message of a command?

前端 未结 3 1576
梦谈多话
梦谈多话 2020-12-05 06:26

How can I suppress error messages for a shell command?

For example, if there are only jpg files in a directory, running ls *.zip gives an e

3条回答
  •  庸人自扰
    2020-12-05 06:58

    Most Unix commands, including ls, will write regular output to stdout and error messages to stderr so you can use bash redirection to throw away the error messages while leaving the regular output in place:

    ls *.zip 2> /dev/null
    

提交回复
热议问题