Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the tee command of Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge of this article "how to use the tee command of Linux", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use the tee command of Linux" article.

The tee command is used to redirect data to a file and, on the other hand, to provide a copy of the redirected data as a stdin for subsequent commands. To put it simply, redirect the data to a given file and screen.

How to use tee

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

[root@localhost ~] # free-h | tee mem.txt total used free shared buff/cache availableMem: 1.8G 164m 1.2G 9.6m 387m 1.5GSwap: 2.0G 0B 2.0g

You can look at the mem.txt file and see that the output has been saved to mem.txt.

Write to multiple files

Tee can write to multiple files, each separated by spaces.

[root@localhost ~] # free-h | tee mem1.txt mem2.txt mem3.txt total used free shared buff/cache availableMem: 1.8G 165m 1.2G 9.6m 389m 1.5GSwap: 2.0G 0B 2.0G append content to the bottom of the existing file

The following example uses the option-a to append content to the bottom of the file without overwriting the original content.

[root@localhost] # free-h | tee-a mem.txt total used free shared buff/cache availableMem: 1.8G 165m 1.2G 9.6m 389m 1.5GSwap: 2.0G 0B 2.0G

As you can see, new content is appended to the bottom of the mem.txt file.

If you do not want to output content on the screen, you can use > standard output symbol to redirect to / dev/null:

[root@localhost] # free-h | tee-a mem.txt > / dev/null the above is about "how to use the tee command of Linux". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about it, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report