Login | Sign up

May 25


0

Intro to piping

Comments (0)

Piping is one of the many great features of Linux that makes its command line so superior. You can send the output of one command to the input of another.

In the Linux terminal, you can send output from one command to another, instead of displaying it to the screen. This allows programs to be focused on specific tasks and furthermore allows you to combine programs to save time.

In order to send output from one command to another, you separate the commands with a | character. This is called a pipe.

  1. <command1> | <command2>

You can pipe as many times as your want.

  1. <command1> | <command2> | <command3>

The previous example will send the output of command1 to command2. The output from command2 is then sent to command3. You can keep piping like this.

Examples

  1. iptables -L INPUT -n | grep 192.168.1.4
  2. sort myfile.txt | uniq

In the first example, iptables -L INPUT -n will output the list of firewall rules in your INPUT chain. This output will not be displayed, instead it will be sent to grep which will search the output for the string 192.168.1.4 and only output the lines that contain that IP address.

In the second example, sort myfile.txt will sort the lines in the file myfile.txt in memory and send the sorted lines to uniq which will only display the unique lines.

Tags:

Comments

There are no comments yet.


Post a new comment

Note: Items marked * are required fields

Post a comment

You must login before you can do that.

If you don't have an account, register for free. It's completely private.

Why register

  • rate posts and comments
  • ask questions about posts
  • request new topics/tutorials
  • mark posts as favorites to easily find them again