Why does the
who > lp creates a file but
who | lp leads the output to program
What is the underlying principle behind these two simple commands? Can somebody explain it with an example?
> is redirection to a file.
| is a redirection to a process through the use of a pipe.
The latter essentially points file descriptor 1 (
STDOUT) of one process to a pipe which leads to file descriptor 0 (
STDIN) of another process. A file redirection operation is not as complex, it merely takes an FD and dumps it to a file.