理解Unix/Linux中标准的输入输出流中字母所代表的含义

HandleNameDescription
0stdinStandard input, Use to get input (keyboard)
1stdoutStandard output, Use to write information (screen)
2stderrStandard error, Use to write error message (screen)
  • > 标准输出重定向,与 1> 一样

  • 2>&1 将标准错误输出重定向到标准输出

  • > filename

示例

重定向标准错误输出到文件
$ program-name 2> error.log
$ command1 2> error.log
重定向标准输出和标准错误输出到文件
$ command-name &>file

或者

$ command > file-name 2>&1
不输出信息
$ command &> /dev/null

https://www.cyberciti.biz/faq/redirecting-stderr-to-stdout/

Logo

更多推荐