linux命令之tee,linux tee命令详解

最近在服务器调试东西的,在输出内容的同时也需要把内容输出到一个指定的文件,这个时候tee命令是我们的首选,接下来吾爱编程就为大家介绍一下tee 命令使用详解,有需要的小伙伴可以参考一下:

1、简介:

tee命令用于将标准输入复制到每个指定文件,并显示到标准输出。tee指令会从标准输入设备读取数据,将其内容输出到标准输出设备,同时保存成文件。

2、语法:

tee [选项]... [文件]...

3、参数:

-a, --append内容追加到给定的文件而非覆盖

-i, --ignore-interrupts忽略中断信号

--help显示此帮助信息并退出

--version显示版本信息并退出

如果文件指定为"-",则将输入内容复制到标准输出

4、实例:

(1)、在输出到控制台的时候,将内容保存到itbianhcneg.log

[root@localhost ~]# ping www.itbiancheng.com | tee itbiancheng.log

PING www.itbiancheng.com.cname.yunjiasu-cdn.net (58.211.137.139) 56(84) bytes of data.

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=1 ttl=56 time=12.5 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=2 ttl=56 time=12.6 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=3 ttl=56 time=12.3 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=4 ttl=56 time=12.0 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=5 ttl=56 time=11.3 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=6 ttl=56 time=11.5 ms

(2)、往已有文件追加内容,这个时候我们可以使用-a参数来实现:

[root@localhost ~]# ping www.itbiancheng.com | tee -a itbiancheng.log

PING www.itbiancheng.com.cname.yunjiasu-cdn.net (58.211.137.139) 56(84) bytes of data.

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=1 ttl=56 time=11.3 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=2 ttl=56 time=11.4 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=3 ttl=56 time=11.9 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=4 ttl=56 time=11.3 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=5 ttl=56 time=12.5 ms

(3)、将内容输出到多个文件,我们直接在tee命令后面直接添加对应的文件:

[root@localhost ~]# ping www.itbiancheng.com | tee itbiancheng.log www.log

PING www.itbiancheng.com.cname.yunjiasu-cdn.net (58.211.137.139) 56(84) bytes of data.

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=1 ttl=56 time=11.2 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=2 ttl=56 time=13.0 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=3 ttl=56 time=10.9 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=4 ttl=56 time=13.2 ms

(4)、忽略中断事件,这个时候我们可以使用-i参数:

[root@localhost ~]# ping www.itbiancheng.com | tee -i itbiancheng.log

PING www.itbiancheng.com.cname.yunjiasu-cdn.net (58.211.137.139) 56(84) bytes of data.

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=1 ttl=56 time=13.0 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=2 ttl=56 time=11.3 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=3 ttl=56 time=11.6 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=4 ttl=56 time=13.1 ms

64 bytes from 58.211.137.139 (58.211.137.139): icmp_seq=5 ttl=56 time=12.4 ms

  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值