Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 230
Kristopher Ives Avatar asked Jul 09 '10 19:07

Kristopher Ives


People also ask

Can we redirect the output of a command to a file and display at the same time?

Redirecting output to Multiple files and screen: If you want to redirect the screen output to multiple files, the only thing you have to do is add the file names at the end of the tee command.

How do you log a terminal output?

Simply right-click on the terminal and press “Copy output as HTML.” This will, then, load the terminal text into your clipboard. From there, you can paste it to any text editor.


1 Answers

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.

like image 173
Matthew Flaschen Avatar answered Sep 17 '22 18:09

Matthew Flaschen