Data flow redirection is the transfer of a command that should appear on the screen to other places after execution
Standard
1, standard input (stdin): code 0, using < or <<
2, standard output (stdout): Code is 1. , using > or >>
3, standard error output (stderr): code 2, using 2> or 2>>
Standard output and standard error Output
Simply put, the standard output value is the correct information that is returned by the command execution, and the standard error output can be understood as the error message after the command execution failed.
Example:
Correct and error data written in two different files
[Email protected]:/mnt/c/users/vivi# find/home-name bashrc > List_right 2> list_error
Correctly writes to the same file as the error data
[Email protected]:/mnt/c/users/vivi# find/home-name BASHRC > List 2>&1
[Email protected]:/mnt/c/users/vivi# find/home-name. BASHRC &> List
/dev/null garbage bin black hole equipment and special wording
if we know that the error message will occur, do we want to ignore the error message and not display or store it? This time the black hole device /dev/null is very important, this /dev/null can eat any information directed to this device
Example:
[Email protected]:/mnt/c/users/vivi# find/home-name BASHRC 2>/dev/null
Standard input:< and <<
in the simplest terms, it is to replace the data that is required to have the keyboard input into the contents of the file, and let 's take a look at what keyboard input is called by the Cat command.
Example: A simple process for creating a file with the cat command
[Email protected]:/mnt/c/users/vivi# cat > Catfile
Testing
Cat file Test
<== here, press "Ctrl"+d to leave.
The following is a plain text file instead of keyboard input
Example:
[Email protected]:/mnt/c/users/vivi# cat > Catfile < ~/.BASHRC
[Email protected]:/mnt/c/users/vivi# ll Catfile ~/.BASHRC
-rwxrwxrwx 1 root root 3106 June 16:05 catfile*
-rw-r--r--1 root root 3106 Feb 2014/ROOT/.BASHRC
After understanding < , let 's look at the << symbol, which represents the meaning of the end input, for example, we want to use the cat Outputs the input information directly to the catfile . And when EOF is entered by the keyboard , the input ends
[Email protected]:/mnt/c/users/vivi# cat > Catfile << "EOF"
> This is a test
> OK now stop
> EOF
<== input eof this keyword, immediately end without the need to enter "Ctrl"+d
[Email protected]:/mnt/c/users/vivi# cat Catfile
This is a test
OK now stop
<== only these two lines, there will be no keywords that line
Let's summarize what we need to use command output redirection:
1, the screen output information is very important, and we need to save it when
2, the background execution of the program, do not want her to interfere with the normal output of the screen when
3, Some of the system's routine command may be known error message, want to "2>/dev/null" to throw it away
4. When the error message and the correct information need to be output separately
shell--Data Flow Redirection