Apple - What does 2>&1 | tee mean?

  • 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.


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.

Tags:

Unix

Macos