What is pipeline and how to use it

Share this post to your friends !

This entry is part 2 of 10 in the series Linux commands: Part 6 - Redirection
What is pipeline and how to use it
5 (100%) 1 vote[s]

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 |.

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.

We will do an example using two commands that you already know through previous posts. The ls command and the less command.

what-is-pipeline-and-how-to-use-it What is pipeline and how to use it
What is pipeline and how to use it.

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

Conclusion

You may not feel the power of the pipeline now. In the next article in the series, you will understand it. Keep learning more.

Continue reading the series«« Previous part: Overview of I/O redirection in LinuxNext part: Example of using cat command in Linux »»
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.


Share this post to your friends !
If you appreciate what we share in this blog, you can support us by:
  1. Stay connected to: Facebook | Twitter | Google Plus | YouTube
  2. Subscribe email to recieve new posts from us: Sign up now.
  3. Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
  4. Become a Supporter - Make a contribution via PayPal.
  5. Support us by purchasing Ribbon Lite Child theme being using on this website.

We are thankful for your support.

single post bottom banner
«« »»

Got something to say? Join the discussion

Please keep in mind that all comments are subject to our Comment Policy. Your email address will not be published.
This site uses Akismet to reduce spam. Learn how your comment data is processed.