How to log output in bash and see it in the terminal at the same time?

Kristopher Ives picture Kristopher Ives · Jul 9, 2010 · Viewed 43.8k times · Source

I have some scripts where I need to see the output and log the result to a file, with the simplest example being:

$ update-client > my.log

I want to be able to see the output of the command while it's running, but also have it logged to the file. I also log stderr, so I would want to be able to log the error stream while seeing it as well.

Answer

Matthew Flaschen picture Matthew Flaschen · Jul 9, 2010
update-client 2>&1 | tee my.log

2>&1 redirects standard error to standard output, and tee sends its standard input to standard output and the file.