pipes vs. redirects

23

4

I've been using pipes and redirects for a long time and just realized that I don't know exactly how they are different. I just know that if you want to store the output in a file, then you use >. Otherwise most of the time you just use |. Can someone explain the difference between pipes and redirects?

tony_sid

Posted 2011-04-30T05:30:04.420

Reputation: 11 651

possible duplicate of Is backwards redirection the same as a pipe?

– Wuffers – 2011-05-05T03:37:01.037

Answers

25

The both do the same basic thing; they redirect a file descriptor of the process executed. The difference lies in how. A pipe connects the stdout of one process to the stdin of another, whereas redirection redirects from/to a file (> from stdout to a file, < from a file to stdin).

Ignacio Vazquez-Abrams

Posted 2011-04-30T05:30:04.420

Reputation: 100 516

1The distinction sort of blurs in Linux and other systems that have /dev/fd. For example, if you run echo foo > >(somecommand), it will expand to echo foo > /dev/fd/3. It's still redirection, but to a process. – user1686 – 2011-04-30T18:43:30.493