/* Configure /*-----------------------------------------------------------------------------------------------
@ Blackeye poet <www. chenwei. ws>
Optional -----------------------------------------------------------------------------------------------*/
Role of input/output redirection:
Output redirection saves the command execution result to a file for easy viewing.
Input redirection is to change the original keyboard input to file input.
First, let's take a look at the standard input and output:
[Device] [device file name] [file descriptor] [type]
Keyboard/dev/stdin 0 standard input
Display/dev/stdout 1 standard output
Display/dev/stderr2Standard Error output
Concepts (> Overwrite,> append)
[Correct output redirection]
Command> file # overwrite the command and output it to a file or device.
Command> file # append the command to the correct output to a file or device.
[Error output redirection]
Error command 2> file # overwrite the output of command errors to the specified file or device
Error command 2> file # output the command error to a specified file or device in append Mode
(Note: To save the error message, you must add 2 before the single sign or double sign, with no space in the middle)
[Correct output and error output are saved at the same time]
1. Command> File2> & 1# Store both the correct and error outputs to the same file in overwrite Mode
2. Command> file 2> & 1 # Save both the correct and error outputs to the same file in append mode.
3. Commands&> File # is equivalent to the first one (& the role is equivalent to 2> & 1)
4. Command &> file # is equivalent to the second
5.Command> file a 2> file B# Append the correct output to file a and append the wrong output to file 2 (useful during regular backup)
Ls&>/Dev/null# Save the execution result to/dev/null (devices that do not exist are about to clear meaningless results)
Input redirection:
[WC for keyboard input statistics]
WC [-C] file name # count the number of bytes
WC [-W] file name # count the number of words
WC [-L] file name # Number of Statistics rows
(After WC is input, other characters will be counted. CTRL + D ends)
(4 rows, 7 words, 40 characters)
[WC Statistical File: a unit smaller than the number]
Bytes ---------------------------------------------------------------------------------------------