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

An example Analysis of Shell output Redirection

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the relevant knowledge of Shell output redirection case analysis, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this Shell output redirection case analysis article. Let's take a look at it.

The Linux command takes input from the standard input device (stdin) by default and outputs the results to the standard output device (stdout) for display. In general, the standard input device is the keyboard, and the standard output device is the terminal, that is, the display. The output of the command can not only be a monitor, but can also be easily transferred to a file, which is called output redirection.

Shell output redirection is typically achieved by inserting specific symbols between commands. In particular, the syntax of these symbols is as follows:

Command1 > file1

The above command executes command1 and then stores the output in file1.

Note that any existing content in the file1 will be replaced by the new content. If you want to add new content to the end of the file, use the > > operator.

Example

Execute the following who command, which redirects the complete output of the command in the user file (users):

$who > users

After execution, no information is output at the terminal because the output has been redirected from the default standard output device (terminal) to the specified file.

You can use the cat command to view the contents of the file:

$cat users_mbsetupuser console Oct 31 17:35tianqixin console Oct 31 17:35tianqixin ttys000 Dec 1 11:33

Output redirection overwrites the contents of the file, as shown in the following example:

$echo "tutorial: www.yisu.com" > users$ cat users tutorial: www.yisu.com$

If you do not want the contents of the file to be overwritten, you can use > > to append to the end of the file, for example:

$echo "tutorials: www.yisu.com" > > users$ cat users tutorials: www.yisu.com tutorials: www.yisu.com$ input redirection on "Shell output redirection instance analysis" this article ends here, thank you for reading! I believe you all have a certain understanding of the knowledge of "Shell output redirection case analysis". If you want to learn more, you are welcome to 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