Home > Article > Operation and Maintenance > What does pipeline in Linux mean and what does redirection mean?
In Linux, a pipe is a one-way communication mechanism between two processes; the output data of one program can be input to another program through this channel. Redirection refers to modifying some of the original default things and changing the default execution method of the original system commands.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
Friends who are familiar with operating systems often hear and use the words pipeline and redirection. So what is a pipeline and what is redirection? Will they be useful to me? It can be said that pipelines and redirection are one of the essences of the operating system. The functions of pipelines are inseparable from all aspects of the operating system's processes, programs, and management. As for redirection, it is one of the most commonly used methods by system administrators. First, we can say without exaggeration that without pipes and redirections, it is simply impossible to manage Linux.
Definition: A pipe is a mechanism for one-way communication between two processes.
Anyone who has studied operating systems knows that this one-way communication mode is called half-duplex. Because of the unidirectional nature of pipes transmitting data, pipes are also called half-duplex pipes, and this unidirectionality cannot be changed once determined.
The pipeline in Linux can input the output data of one program to another program through this channel. The pipeline in Linux is implemented through the symbol |
.
Definition: Linux redirection refers to modifying some of the original default things and changing the default execution method of the original system command.
For example, if I don’t want to see the output on the monitor but want to output it to a certain file, I can do this through Linux redirection. Linux's redirection mechanism is implemented through the symbols , represents output.
Standard output in redirection:
An example is given in the figure below to illustrate briefly:
The creation method of txt2 in cat txt1 txt2 in the redirection command is:
1. If the file does not exist, the system will automatically create it;
2. When the file already exists, the system will first clear the file and then write the data;
3. That is to say, if you use > to output to an existing file, That file will be overwritten.
4. If you want to retain the previous content, you need to use two redirection symbols>>.
Error output in redirection:
The above introduction is based on the premise that correct results can be obtained. What if I want to find something now, but it happens to be unreachable? This requires error log. In Linux, 1 represents standard output and 2 represents error output. For example:
1>: Output the correct data to the specified file or device using the overwrite method;
1>>: Output the correct data to the specified file using the append method to the file or device;
2>: Output the incorrect data to the specified file or device by overwriting;
2>>: Output the incorrect data to the specified file or device by appending Data is output to the specified file or device.
Note: There is no space between 1 or 2 and >.
Standard input in redirection:
Before learning its standard input, let’s talk about how to get data from the keyboard.
## After learningLinux Video Tutorial"
The above is the detailed content of What does pipeline in Linux mean and what does redirection mean?. For more information, please follow other related articles on the PHP Chinese website!