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

What are the input and output methods of Linux

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces "what are the input and output methods of Linux". In the daily operation, I believe that many people have doubts about the input and output methods of Linux. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "what are the input and output methods of Linux?" Next, please follow the editor to study!

There are three kinds of standard input and output in linux, which are STDIN,STDOUT,STDERR, and the corresponding number is 0Person1Pol 2.

STDIN is standard input and reads information from the keyboard by default

STDOUT is standard output. By default, the output result is output to the terminal, that is, a display or something like that.

STDERR is a standard error message and is also displayed on the terminal by default.

Since both STDOUT and STDERR are displayed on the terminal by default, in order to distinguish the information between the two, there is a definition of the numbered 0Magne1Person2, which uses 1 to represent STDOUT,2 to represent STDERR.

The following examples are given:

Log in as an ordinary user (Cent OS 7) and execute the find / etc-name passwd command. By default, the command execution result (STDOUT) and error message (STDERR) will be output to the terminal display.

Try the role of number 1 name passwd 2, find / etc-name passwd 1 > find.out 2 > find.err, where STDOUT and STDERR are stored in find.out and find.err, respectively.

Personal understanding is that the execution result output of the find / etc-name passwd command the correct output (STDOUT) is received by 1 and the error message (STDERR) is received by 2.

To display all output and error messages, you can use & to represent all 1 and 2 information, such as:

Find / etc-name passwd & > find.all

Sometimes you want to redirect the wrong information to the output, that is, if you redirect the result of 2 to 1, you will have the idea of "2 > 1". If you follow the above writing, the system will redirect the wrong information (STDERR) 2 to a file named 1 by default, rather than what you think (STDOUT). Therefore, it is necessary to add & to make a distinction. There is a usage like 2 > & 1:

Find / etc-name passwd 2 > & 1 | less

Sometimes you can see the usage like this:

Find / etc-name passwd & 2 > & 1 | less

Here it can be broken down into

Find / etc-name passwd & indicates that the previous command is executed in the background.

2 > & 1 | less means to redirect the error message to standard output and display it in pages using less.

At this point, the study of "what are the input and output methods of Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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