| tee 命令用于读取标准输入的数据,将内容输出到屏幕,同时保存成文件,并且可以保存到多个文件。 |
tee最基本的用法就是显示输出结果并且保存内容到文件中。下面例子使用
free
命令显示系统内存使用信息,并使用
tee命令将信息输出到屏幕,并保存到文件mem.txt中。
[root@localhost ~]# free -h | tee mem.txt total used free shared buff/cache available Mem: 1.8G 164M 1.2G 9.6M 387M 1.5G Swap: 2.0G 0B 2.0G
可以查看一下mem.txt文件,可以看到输出内容已经保存到mem.txt里面了。

tee可以写入多个文件,每个文件之间使用空格分隔。
[root@localhost ~]# free -h | tee mem1.txt mem2.txt mem3.txt total used free shared buff/cache available Mem: 1.8G 165M 1.2G 9.6M 389M 1.5G Swap: 2.0G 0B 2.0G

下面的例子使用选项
-a在文件底部追加内容,不覆盖原有内容。
[root@localhost ~]# free -h | tee -a mem.txt total used free shared buff/cache available Mem: 1.8G 165M 1.2G 9.6M 389M 1.5G Swap: 2.0G 0B 2.0G
可以看到,在mem.txt文件底部追加了新的内容。
如果不想在屏幕输出内容,可以使用
>标准输出符号,重定向到
/dev/null中:
[root@localhost ~]# free -h | tee -a mem.txt > /dev/null
tee命令用于读取标准输入的数据,将内容输出到屏幕,同时保存成文件,并且可以保存到多个文件。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31524109/viewspace-2762519/ ,如需转载,请注明出处,否则将追究法律责任。