Intro to piping
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.
<command1> | <command2>
You can pipe as many times as your want.
<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
iptables -L INPUT -n | grep 192.168.1.4sort 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.




linux

Comments
There are no comments yet.