数据流
-
stdin:标准输入,代码为0。
-
stdout:standard output,标准输出,指执行命令后返回的正确信息。代码为1。1可以省略。
-
stderr:standard error output,标准错误输出,指执行命令失败后返回的错误信息。代码为2。
重定向符号
输出重定向
>
:覆盖原有内容>>
:在原有内容上追加
输入重定向
<
:将原本由键盘输入的数据,由文件内容取代<<
:从标准输入中读入,直到遇见分界符停止
示例
-
>
等于1>
:以覆盖的方式将正确的输出重定向到文件或装置上
[test@study ~]$ ll > list.txt
[test@study ~]$ ll 1> list.txt
-
2>
:以覆盖的方式将错误的输出重定向到文件或装置上
[test@study ~]$ find / -name test 2> find.txt
-
>>
等于1>>
:以追加的方式将正确的输出重定向到文件或装置上
[test@study ~]$ ll >> list.txt
[test@study ~]$ ll 1>> list.txt
-
[test@study ~]$ 2>>
:以追加的方式将错误的输出重定向到文件或装置上
[test@study ~]$ find / -name test 2>> find.txt
-
2>&1
等于&>
:以覆盖的方式将正确与错误的输出重定向到一个文件或装置中。相反,也有1>&2
。
[test@study ~]$ find / -name test > find.txt 2>&1
[test@study ~]$ find / -name test &> find.txt
-
>> file 2>&1
等于&>>
:以追加的方式将正确与错误的输出重定向到一个文件或装置中
[test@study ~]$ find / -name test >> find.txt 2>&1
[test@study ~]$ find / -name test &>> find.txt
-
<
:cat > catfile < source
将source文件的内容写入catfile文件 -
<<
:-bash-4.2$ cat > catfile << "eof" > 123 > 456 > eof -bash-4.2$ cat catfile 123 456