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 realize data flow orientation by Linux

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "how to achieve data flow orientation in Linux". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to achieve data flow orientation with Linux".

The execution of general commands comes from standard input (such as keyboard input, and commands from files are also converted to standard input). After execution, the data (processing results or error messages) are transferred to the screen, that is, standard output. but this leads to a very cluttered screen and is not conducive to saving and viewing the results. We can use data flow orientation to transfer results and error messages to files as follows:

Standard input (stdin): code is 0, using

Standard error output (stderr): code is 2, use 2 > or 2 > >.

The specific usage is as follows:

For example, we want to run a shell script that displays the time and date, and save the results in cal_date.txt:

Next we run the script that displays the birthday and append the result to cal_date.txt:

Note that > > is used here, and if it is >, the content will be replaced rather than accumulated. Next, we modify the shell script to make the cal parameters wrong, then run and output the error message:

You can also output both the correct result and the error message to two files:

If we do not want to see the error message on the screen and do not want to save it, we can simply throw away the error message and use trash can / dev/null. The example is as follows:

Output the correct result and error information to the same file, and you can use the & symbol flexibly:

The command cat can convert the contents of the file to standard output and display it on the screen, as well as write the keyboard input to the screen to write to a new file:

Among them

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

Internet Technology

Wechat

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

12
Report