10

I read the answer by @grg to question “brew formula” installation logs:

brew install <formula> 2>&1 | tee install.log

So where exactly is this install.log file going to end up, and what exactly the 2>&1 | tee part of the command mean?

  • 2
    The "2>" and "&1" are shell syntax for ; "where the error messages are written to" should go to "where the normal output are written to". – Thorbjørn Ravn Andersen Jun 23 at 16:27
15
  • The tee command prints the piped stdout to the file path given as well as displaying it in the terminal. This is commonly used for recording the output of commands to file which would otherwise only be ephemerally printed to the terminal.

    Without tee and using simple redirection of brew install > install.log would prevent stdout being printed to the terminal as well as the file, requiring the file to be accessed to view the messages.

  • 2>&1 redirects stderr to stdout alongside the existing stdout, meaning that the error messages are redirected as normal output.

    Without this, tee would only print stdout without the error messages to the install log.

install.log is relative to the current directory.

5

2>&1 means "send any error messages (aka 'stderr') to the same output as any informational messages (aka 'stdout")."

And

| tee install.log means "whatever output there is should also be sent to the file install.log.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .