Pipes
With the use of pipes, you can use the output of a program as the input of another one. Below is a simple example using ls command. Example:w3user@ubuntu-a:/usr$ ls -rlt total 152 drwxr-xr-x 10 root root 4096 2008-10-29 18:53 local drwxr-xr-x 2 root root 4096 2008-10-29 18:58 X11R6 drwxr-xr-x 2 root root 4096 2009-02-02 01:33 games drwxrwsr-x 6 root src 4096 2009-02-02 01:33 src drwxr-xr-x 33 root root 12288 2009-02-23 20:39 include drwxr-xr-x 299 root root 12288 2009-03-27 08:31 share drwxr-xr-x 178 root root 61440 2009-03-28 09:00 lib drwxr-xr-x 2 root root 12288 2009-03-28 09:00 sbin drwxr-xr-x 2 root root 36864 2009-03-28 09:01 bin w3user@ubuntu-a:/usr$Now we will run the above command using pipes(adding grep).
w3user@ubuntu-a:/usr$ ls -rlt|grep bin drwxr-xr-x 2 root root 12288 2009-03-28 09:00 sbin drwxr-xr-x 2 root root 36864 2009-03-28 09:01 bin w3user@ubuntu-a:/usr$In the above example, the use of pipe does not display the result of the first command, ls -rlt. Instead the second command, grep is executed on the output of the first command. So the lines that contain the pattern, bin will be listed as the final output.
You can use as many pipes as needed in a single command. Example:
w3user@ubuntu-a:/usr$ ls -rlt|grep bin|sed -e 's/bin/replaced/g' drwxr-xr-x 2 root root 12288 2009-03-28 09:00 sreplaced drwxr-xr-x 2 root root 36864 2009-03-28 09:01 replaced w3user@ubuntu-a:/usr$Here we have used two pipes. You can use as many pipes as needed.
