Linux data redirection
Preparations:
We must understand the output types of data redirection in Linux. There are three types:
Standard input (stdin): the code is 0. Use <(replace the original data) or <(accumulate on the original data)
Standard output (stdout): the code is 1, use> (replace the original data) or> (accumulate on the original data)
Standard Error output (stderr): Code 2, Use 2> (replace the original data) or 2> (accumulate on the original data)
Below are some examples to demonstrate the functions and usage of data redirection.
Standard output and standard error output are stored in different files.
#: Find/home-name. bashrc> list_right 2> list_error
-- Based on the execution of the preceding command, no information is displayed on the screen. You need to view the information after the command is executed in the list_right and list_error files.
Display correct execution information, do not retain error information,/dev/null black hole waste bin can store various Guidance Information
# Find/home-name. bashrc 2>/dev/null
-- Based on the preceding command execution, only the correct execution information is displayed on the screen, and the incorrect execution information is discarded.
3. Save the standard output and standard error output information in the same file.
# Find/home-name. bashrc> list 2> & 1
# Find/home-name. bashrc &> list
-- According to the preceding command execution, we can view the standard output and standard error output information in the list file.
Standard Input <or <
Next we will look at the case Demonstration:
Use the cat command to create a file. We have been using the cat command to view the file before. Next let's take a look at the cat command combined with> creating a file in a targeted way.
# Cat> catfile
> Catfile testing
> Cat file test
> If you create a file by entering data on the keyboard, press ctrl + d to exit.
Use other files to create the same file
# Cat> catfile </etc/issue
-- We can query the information of these two files to see if the sizes of these two files are consistent.
Use the <keyword to enter a data keyword and the result ends immediately.
# Cat> catfile <"out"
> This is a out.
> OK now stop
> Out --- the system ends immediately after the keyword is entered. You do not need to use ctrl + d to exit.
Redirection of input and output in Linux
Linux redirection: redirects stdout and stderr to a file.
Redirection of basic Linux commands
Pipelines and redirection in Linux
Linux Shell file redirection experience
This article permanently updates the link address: