linux管道与重定向

1. 重定向命令

>        输出重定向覆写
>>      输出重定向追加
2>      错误重定向覆写
2>>    错误重定向追加
&>     输出和错误作为同一个流重定向覆写
&>>   输出和错误重定向追加
<       从文件中提取输入信息
<<     从标准输入中读入,直到遇到分解符才停止

set -C 禁止覆写
set +C 允许覆写

2. 管道命令

command 1 | command 2 | command 3 | ...

命令的输出作为下一个命令的输入,默认不支持错误转发,可以使用 |& 符号

2.1 重定向到多个目标

tee命令,可以向stdout输出的同时,向文件也输出内容。

tee [OPTION]...[FILE]...

-a: 追加数据文件
-i: 忽略中断符号

command 1 | tee -a file | command 2 command1的输出保存到文件,并且作为command2的输入
ping test.com | tee -a ping.log ping的结果保存到ping.log文件
ping test.com | tee ping1.log ping2.log ping的结果保存到多个log文件

echo 'hello' | tee /tmp/hello.txt  tee命令是将输入的内容在显示器上打印出来,并保存到/tmp/hello.txt中

原文地址:https://www.cnblogs.com/mengff/p/12881969.html