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

Introduction to linux standard error input and output

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

What the editor shares with you today is the introduction of linux standard error input and output. The output includes two types: one is the running result of the program (standard output), and the other is status and error information (standard error). I believe that many people do not understand, in order to let you know more about linux, so give you a summary of the following content, let's look down. I'm sure you'll get something.

Standard output (standard output) and standard error (standard error), which are connected to the screen by default

Standard input (standard input) is connected to the keyboard by default

You can use IO redirection (redirection) to change the location where inputs and outputs are sent

1. Standard output

Standard output redirection, using the redirection operator (">"), outputs the program to a file, which is rewritten from the file header by default

You can use "> test.txt" to clear the text message

Use "> >" to add the file to the end of the text

2. Standard error

Standard error redirection, use "2 >" for output, because the file stream contains three types, namely, "input, output, error", corresponding to "0,1,2".

That is, ">", which is equal to "1 >", standard output

To handle unwanted error output, use "2 > / dev/null" to hide the error message of a command.

Both output and error are displayed. Standard error is generated after standard output, that is, use ">" first, and then use "2 > & 1". Command: "xxxx > xxxx 2 > & 1"

You can also use "& >" to directly output standard output and errors, the command: "xxxx & > xxxx", available in newer versions of bash.

As shown in the figure:

3. Standard input:

The cat command (ConcATenate), which is meant to link a file, cat xxxx [1] xxxx... > xxxx [end]

If you only use the first parameter, that is, output the information to the screen, you can output a short file without line wrapping.

If you only use cat, get the information from the keyboard and output it to the screen

If only the last parameter, cat > xxxx, is used, it is entered from the keyboard and stored in the file.

If both are used, connect the file, connect the file sequentially, and save it to the end file

You can use "

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

Servers

Wechat

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

12
Report