2

What is difference between the pipe(|) and output(>) redirection operators? Where can I use them?
For eg:
I have normally used pipe(|) only with grep

find . | grep abc

and the only use for input-output redirection I've come across is to test my programs with different input-output
For eg:

abc.exe < in.txt > out.txt

Why can't I do something like:

xyz.exe | out.txt
icedwater
  • 4,701
  • 3
  • 35
  • 50
Kartik Anand
  • 4,513
  • 5
  • 41
  • 72
  • 3
    `|` pipes output to another program while `>` redirects it to file. That's why if you write `xyz.exe | out.txt` you will get error because `out.txt` isn't an executable file. – Eddy_Em Jul 17 '13 at 08:54
  • Related: http://stackoverflow.com/questions/9834086/what-is-a-simple-explanation-for-how-pipes-work-in-bash – fedorqui Jul 17 '13 at 09:17

1 Answers1

2

Pipes (|) are used to string together small (yet focused) programs together to perform complex tasks. This is a core UNIX philosophy.

For example:

$ ps -ef | fgrep http
$ sort myfile | uniq

Redirection (> or 2>) is simply used to redirect standard out (stdout) or standard error (stderr) to a file.

For example:

$ sort myfile | uniq > newfile
$ find / -name andy\* 2>/dev/null
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • So is there a list of these "focused" programs? – Kartik Anand Jul 18 '13 at 14:21
  • @KartikAnand Sorry I missed your comment. No I don't think there is a definitive list; you will probably get a good subset by looking at some UNIX command line guides however. – trojanfoe Jul 23 '13 at 10:45