WriteBash - What is pipeline and how to use it? This article will tell you about a feature that is most powerful in Linux.
Use pipelines that are common in operating Linux systems, if you want to become a Linux system administrator, remember the pipeline.
What is a pipeline?
Shell Linux gives commands the ability to read data from standard input and send data to standard output. This capability is called pipelines.
Here, it seems a bit confusing. Understand it as a way to redirect data. The data from standard output of a command will piped into standard input of another command.
Pipe operator is
| (vertical bar). After a command has this character, it understands that its output data will sent to the next command immediately after the
Recommended Reading: How to control iptables in bash script
Structure the command of a pipeline as follows:
$ command-1 | command-2 | command-n
Example using pipeline
Now that we are going to go into an example of using pipeline in Linux, what will it look like.
Now type the following command to list all content in the
/etc directory. Of course, you already know that the results of the
ls command will return on the terminal screen.
$ ls -l /etc
The problem here, is that the list of content in the
/etc directory can be very long and in one window will not be able to see the whole.
On the terminal of the desktop, you can roll the mouse cursor upwards to see, but if on the console server, you will have trouble with this. Because you will only see part of the
ls command results.
To solve that problem, we will pipe the result of
ls command to
less. You also know that
less can be used to view long content by dividing that content into pages.
Okey, now type the command below and see the results.
$ ls -l /etc | less
Be careful when using > and |
In the previous article, you saw the character
> used to redirect I/O redirection, usually to write the result of the command to file.
Therefore, the redirection operator
> and the pipeline operator
| are two different things, you must be careful when using it.
Warning: Don’t try to use
> instead of
| in the pipeline.
This command is normal:
$ command-1 > file-1
And this command is normal too:
$ command-1 | command-2
This command will be very bad, don’t try to use it.
$ command-1 > command-2
You may not feel the power of the pipeline now. In the next article in the series, you will understand it. Keep learning more.If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.
If you appreciate what we share in this blog, you can support us by:
- Stay connected to: Facebook | Twitter | Google Plus | YouTube
- Subscribe email to recieve new posts from us: Sign up now.
- Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
- Become a Supporter - Make a contribution via PayPal.
- Support us by purchasing Ribbon Lite Child theme being using on this website.
We are thankful for your support.