[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Redirecting stdout and stderr into a file



Upayavira wrote:
Otto Wyss wrote:

Sorry I can't remember how I can redirect the stdout and stderr together
into a file. I can

grep > logfile
grep 2> logfile

but how can I redirect both together?
cat foo 2>&1 > logfile
or, to append to the file:
cat foo 2>&1 >> logfile

Should do it.

Redirections are processed in the order they appear on the command line. So "2>&1 >logfile" redirects stderr to the same as current stdout (normally the terminal) and then redirects stdout to logfile. You need to swap the two redirections to send both streams to logfile.

Ben.



Reply to: