http://www.cpqlinux.com/redirect.html
[root@server /root]# ./cmd 1>out.txt 2>err.txt
[root@server /root]# ./cmd 1>>out.txt 2>>err.txt
[root@server /root]# (((./cmd | tee stdout.txt) 3>&1 1>&2 2>&3\ |tee stderr.txt) 3>&1 1>&2 2>&3) 1>out.txt 2>err.txt
Note: Lines that end in a backslash are continued on the next line. Any such lines should be keyed in as one complete line. The lines are too long to fit on the web page without formatting them this way.
The following will capture a copy of stdout and save it to a file called "stdout.txt"
[root@server /root]# ./cmd | tee stdout.txt
stdout goes through the pipe and tee is able to save a copy of it to the file "stdout.txt"; however, we just lost control of stderr. stderr will not go through the pipe, instead it goes directly to our display.
Lets gain control again of stderr and stdout. We do this by surrounding our command with a set of parenthesis.
[root@server /root]# (./cmd | tee stdout.txt)
Capturing stderr
Now that we have swapped our stdout and stderr, lets hook up tee once again. tee will now capture stderr (tee believes that it is really stdout because stdout is the only thing that can come through the pipe).
[root@server /root]# (./cmd | tee stdout.txt) 3>&1 1>&2 2>&3 \ | tee stderr.txt