当前位置:网站首页>Tee command usage example

Tee command usage example

2022-07-02 09:57:00 Teacher Liu Trent


tee​ ​ command ​​ Used to read standard input data , Output content to screen , At the same time save it as a file , And can be saved to multiple files .

How to use tee

​tee​​​ The most basic usage is to display the output and save the content to a file . The following example uses ​​free​​​ ​ command ​​​ Display system memory usage information , And use ​​tee​​ The command outputs information to the screen , And save to file mem.txt in .

       
[[email protected] ~]# 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
  • 1.
  • 2.
  • 3.
  • 4.

You can have a look mem.txt file , You can see that the output has been saved to mem.txt Inside the .

Tee Command use instance _ The standard input

Write to multiple files

​tee​​ Multiple files can be written , Separate each file with a space .

       
[[email protected] ~]# 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
  • 1.
  • 2.
  • 3.
  • 4.

Tee Command use instance _ The standard input _02

Add content at the bottom of the existing file

The following example uses options ​​-a​​ Add content at the bottom of the file , Don't cover the original content .

       
[[email protected] ~]# 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
  • 1.
  • 2.
  • 3.
  • 4.

You can see , stay mem.txt New content is added at the bottom of the file .

Tee Command use instance _ The standard input _03

If you don't want to output on the screen , have access to ​​>​​​ Standard output symbol , Redirect to ​​/dev/null​​ in :

       
[[email protected] ~]# free -h | tee -a mem.txt > /dev/null
  • 1.

summary

tee Command is used to read standard input data , Output content to screen , At the same time save it as a file , And can be saved to multiple files .



原网站

版权声明
本文为[Teacher Liu Trent]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202151655262449.html