Get the App
SLTechnology News&Howtos  ›  Servers  › 

Introduction to linux standard error input and output

Shulou Source: shulou.com Published: 2022-06-03 06:54:01 10月02日 Update

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 "

Tags: Output standard error file input information command content screen keyboard parameter text program same position at the same time head that is tail meaning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology NVidia vpn Shulou Information Huawei