Example Analysis of Pipeline and Redirection in linux
This article mainly introduces the example analysis of pipeline and redirection in linux, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
In linux system, most commands are very simple, and there are few commands with complex functions. Each command often implements one or more very simple functions. We can complete complex functions by combining multiple simple commands.
Almost all commands in linux return plain text, because commands are run under CLI, and plain text is the input format of the command line, which makes command collaboration possible. The combination of commands is done through redirection and plumbing mechanisms.
The data flow on the command line is defined as follows:
Standard input description number default
STDIN standard input 0 keyboard
STDOUT standard output 1 terminal
STDEER Standard error 2 Terminal
Through piping and redirection, we can control the data flow of CLI.
Redirect
> redirect standard output to a file. If the file does not exist, then create the file, and the existence will overwrite the original content.
> > redirect standard output to a file. If the file does not exist, create the file and append the content to the end of the file if it exists.
2 > redirect standard error to a file
2 > & 1 redirect standard error and standard output to a file
< redirect standard input
Pipeline
Use the standard output of the first command as the standard output of the next command.
Thank you for reading this article carefully. I hope the article "sample Analysis of pipes and Redirects in linux" shared by the editor will be helpful to you. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!