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

文章知识点与官方知识档案匹配,可进一步学习相关知识CS入门技能树Linux进阶新增用户24986 人正在系统学习中 相关资源:EXCEL数据核对数据对碰软件(增加模糊对比)_EXCEL数据核对-专业…

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年3月25日
下一篇 2021年3月25日

相关推荐