Linux标准输入命令tee详解

在Linux中,tee命令用于读取标准输入的数据,将内容输出到标准输出设备,同时保存为文件。需要注意的是,在使用管道符时,tee无法读取前一个命令的标准错误输出。

基本语法

tee [参数] [文件...]

参数说明

参数 说明
-a 或 --append 附加到现有文件
-i 或 --ignore-interrupts 忽略中断信号
--help 显示帮助
--version 显示版本

举例

who | tee <file>
pwd | tee -a <file>
# 同时保存到file1和file2中
tee <file1> <file2>
# 输出到标准输出两次
tee -
# 输出两次且同时保存到file1和file2中
tee <file1> <file2> -

练习题

比如tee命令与重定向。

seq 5 > a.txt
cat a.txt > b.txt
cat a.txt | tee c.txt
cat a.txt >> b.txt
cat a.txt | tee -a c.txt

原创文章禁止转载:技术学堂 » Linux标准输入命令tee详解

精彩评论

9+8=

感谢您的支持与鼓励

支付宝扫一扫打赏

微信扫一扫打赏