Log as well as see error and standard output in Linux Terminal

Quick snippet, as I was searching for this one today.

You can output both standard and error output to both screen and log file with the below command:

my_command.sh 2>&1 | tee my_command.log

Explanation:

  • my_command.sh
    • replace with your command (possibly including arguments)
  • 2>&1
    • redirects standard error to standard output, otherwise only standard output is written to file
  • | tee
    • my_command.log pipes the output to tee, which writes both to screen and file

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.