$ who >temp #temporary file to hold output of who
$ sort temp
But can bypass this inelegant and inefficient use of temporary file by using a pipe (|) that connects the standard output of one program to the standard input of another program.
$ who | sort | is the pipe operator. creates a pipeline
Here, who's output is redirected (sent thru the pipe) to sort's input. Shell connects the programs together. Standard output of who is piped to standard input of sort.
$ ls -l | more #page at a time directory listing
$ ls | wc -l
Programs in a pipeline (not limited to two programs, can have longer
pipes, e.g. who|sort|lpr) run at the same time, not one after the
other. Kernel looks after synchronization and buffering.
$ ps ax | wc -l
$ ps -aux | grep billybob | wc -l #number of processes billybob has
$ file /usr/bin/* | grep script #which cmds in /usr/bin are scripts
$ cut -d: -f1 /etc/passwd | sort | more #sorted list of usernames
$ wc * | tail -1
Powerful processing by connecting programs in a pipeline. Commands as single-step tools that can be joined together to do complex tasks. Pipe as the single most elegant mechanism in Unix.
Program by composition, not by custom-building. Reuse instead of re-create.