Skip to content

Instantly share code, notes, and snippets.

@mk100120
Last active May 9, 2018 05:44
Show Gist options
  • Save mk100120/a3f695aa519bdd9806928f8de8ccdca9 to your computer and use it in GitHub Desktop.
Save mk100120/a3f695aa519bdd9806928f8de8ccdca9 to your computer and use it in GitHub Desktop.
输入重定向: <
输出重定向: >
标准输入: 0
标准输出: 1
错误输出: 2
Linux Shell 环境中的输入输出重定向,用符号<和>来表示。0、1和2分别表示标准输入、标准输出和标准错误。
1.重定向标准输出到文件:
cat foo > foo.txt
2.重定向标准错误到文件
cat foo 2> foo.txt
3.重定向标准输出到标准错误
cat foo 1>&2
4.重定向标准错误到标准输出
cat foo 2>&1
5.重定向标准输出,标准错误到同一个文件
cat foo > foo.txt 2>&1或cat foo &> foo.txt
这里第个顺序很重要,先把标准输出重定向到文件,再把标准错误输出到标准输出,因为标准输出已经重定向到文件,所以标准错误与重定向到文件。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment