Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Why does the who > lp creates a file but who | lp leads the output to program lp?

What is the underlying principle behind these two simple commands? Can somebody explain it with an example?

share|improve this question
    
A common mistake here is to think that lp file.txt and (for example) cat file.txt | lp are the same (that is, that the pipe somehow assemblies the file, row by row, and makes an argument of that data, and passes it to lp) - this is a common mistake, because the result (in this case, what is printed) may be identical. But those interfaces (argument(s), and a pipe to STDIN) are not at all the same. As an illustration, try it with echo, and not lp. –  Emanuel Berg Nov 20 '12 at 22:43
add comment

1 Answer

up vote 5 down vote accepted

> 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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.