What makes Linux stand out from your average commercial ™ operating system?
There are many helper apps and utilities, together they make a weapon of epic-ness that process, cut, strip, filter and mangle input (stdin) and output (stdout).
stdin can be your keyboard, a file on disk, or even the output from another command. stdout is your screen or a file. That’s the simplified version.
The | (pipe) connects two commands together by their stdin and stdout. We say it pipes the output from one command into another.
*A knife made of pipes*
To print a file to screen, we concatenate (cat) it, we can filter lines with the name ‘monkey’:
$ cat chatlog.txt | grep "monkey"
>
> Jul 22 06:32:00 How do you like your tea, monkey?
> Jul 22 06:32:19 I like my tea with a spot of milk.
I love tea and contrived examples.
Let’s cut out the date/time/nick part, and get a count of the number of words we wrote. Don’t fret about commands you don’t understand, the point is to demonstrate how the swiss army knife works as a whole.
$ cat chatlog.txt | grep “monkey” | cut -b28- | wc -w
> 20
See how each tool does one thing, and it does it well. We just chain the tools together.
We can grep, sed, sort, diff, awk, cmp, cat, tac, join, cut, and much much more.
These Linux tools aren’t without a sense of humor:
‘tac’ prints a file in reverse, the opposite of ‘cat’.
‘more’ prints output a screen at a time.
‘less’ is more: output becomes a vi-like text viewer, with a search function with scrolling back and forth.
‘tail’ is useful to show the last lines in a file, like messages or log entries.
*Meet FIFO, she’s a pipe*
I’ve shown you unnamed pipes, and now I want you to meet FIFO, she is a pipe.
FIFO means “First In, First Out”: whatever goes into the pipe first, will come out the other side first. Just like a normal pipe carrying water or toxic green sludge.
We create a named pipe with mkfifo:
mkfifo monkeypipe
Anything we write to the pipe (cat file > monkeypipe) can be read by another process (cat monkeypipe).
Named pipes is one way for programs to communicate with another. Your music player for example, listens on a special pipe for any commands you may give it, to pause the song or skip to the next track.
Some say named pipes is a fundamental feature of Linuxes and Unices, at least via the CLI. Other ™ operating systems only have named pipe access via coded API calls, and that’s no good nor fun.
*Substitution is better than the real thing*
Wrapping commands in (parenthesis) runs those commands in a subshell, and when you prefix it with < or > the output is redirected to a named pipe, which for all intents and purposes acts like a normal file.
““On a UNIX system, everything is a file; if something is not a file, it is a process.”
So if ‘diff’ compares two files, we can compare two directories by substituting the ‘ls’ output to a named pipe, and feeding those to diff, which sees them as files to read from.
This will compare process lists on two machines, one local, the other remote, via ssh:
diff <(ps axo comm) <(ssh user@host ps axo comm)
(example taken from linuxtutorialblog.com)
*To wit*
What useful applications for pipes do you? Share some of your favorites with us :)

August 2nd, 2011
Wez
Posted in 

I get the basic idea but some of those crazy commands make my head spin :D
I know! Luckily Google helps us out in that dept ;)