Monday, December 6, 2010

Using pipes in Linux


In Linux piping is quite useful.  A pipe channels the output of one program to the input of another. It allows programs to be chained together. Programs in the chain run concurrently.

Use the vertical bar: |  for piping. Sometimes known as the ‘pipe’ character
Programs don’t need to do anything special to use pipes. They read from stdin and write to stdout as normal.

For example, pipe the output of echo into the program rev (which reverses each line of its input):

  $ echo Happy Birthday! | rev
 
!yadhtriB yppaH



Here the output of the first command echo is Happy Birthday!. This is given as the input of the second command in pipe. rev command reverses the string given after it. Thus we get the above output.


Look at another example. To connect the output of echo to the input of wc:

$ echo "count these words, boy" | wc

1       4       23 







0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes