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/