Linux standard input and output error detailed

Source: Internet
Author: User
Tags linux

The output consists of two types: one is the running result of the program (standard output), the other is state and error information (standard error).

Standard outputs (standard output) and standard error (standard error) are connected to the screen by default;

The standard input (standard input) is connected to the keyboard by default;

You can use IO redirection (redirection) To change the input, output location of the transmission;

1. Standard output

Standard output redirection, using the redirection operator (">") to output the program to the file, by default, from the file header rewrite write;

can use "> test.txt", empty text information;

Use ">>" to add the file to the tail of the text;

2. Standard error

Standard error redirection, using "2>", for output, because the file stream contains three kinds, namely "input, output, error", corresponding "0, 1, 2";

namely ">", namely equal to "1>", standard output;

Handle unwanted error output, using "2>/dev/null" to hide the error message for a command.

At the same time display output and error, standard error is produced after the standard output, that is, first use ">", and then use "2>&1", Command: "XXXX > xxxx 2>&1";

can also use "&>", direct output standard output and error, command: "xxxx &> xxxx", newer than the new bash provides.

As shown in figure:

3. Standard input:

Cat command (CONCATENATE), is intended to link files, cat xxxx[1] xxxx ... > xxxx[end];

1. If you only use the first parameter, that is, the output of the information to the screen, you can output a short file, do not wrap;

2. If only cat is used, obtain the information from the keyboard and output it to the screen;

3. If only use the last parameter, that is, Cat > xxxx, that is, input from the keyboard, stored in the file;

4. If all uses, then is the connection file, the file is connected sequentially, and is deposited at the end file;

5. You can use "<", that is, "Cat < XXXX", is redirected, the input source into the file, and the direct input file meaning the same.

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.