Linux shell redirection
Even though I googled and used this many time, I always forgot about all these: &2>1
, 1>2&
, 1>&2
. So I hope that
writing it down myself can help to remember their rule.
Linux file descriptor
- 0: stdin
- 1: stdout
- 2: stderr
Redirect to a file name
Redirect output to a file named 1
Redirect stdout/stderr to a file named 1
Redirect both stdout and stderr to a file named 1
Redirect to a file descriptor
stderr and Pipes
This won’t work
If we want to pipe the stderr, have to redirect stderr to stdout first
Reference
http://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout
http://www.tldp.org/LDP/abs/html/io-redirection.html