HN2new | past | comments | ask | show | jobs | submitlogin

Here's a cheat sheet which should cover the most common situations.

Send stdout to a file.

ls myFileWhichExists > myStdLog

- or -

ls myFileWhichExists 1> myStdLog

Send stderr to a file.

ls myFileWhichDoesNotExist 2> myErrLog

Send stdout to one file and stderr to a different file.

ls myFileWhichExists myFileWhichDoesNotExist 1> myStdLog 2> myErrLog

Send stdout and stderr to the same file

ls myFileWhichExists myFileWhichDoesNotExist 1> myBothLog 2>&1

I read that last part "2>&1" as "Send stderr (2) to the same place as stdout (1) is already going to".

Notice that if you send stdout and stderr to the same file, because of caching and other issues, the output from stdout and stderr will overlap in unpredictable ways.



Yeah, it's the ampersands and ordering and placement and numbers that always throw me, not the concepts. Thanks1




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: