In Unix, how can I output text from a command to the screen while also saving it to a file?

You can use the tee command to output text from a command both to the screen and to a file. The tee command takes data from standard input and writes it to standard output as well as to a file.

For example, without the tee command, you would be forced to redirect the output of the who command to a file, and then print the file to the screen with two separate commands. In other words, to redirect the output of the who command to the file who_output and then print it to the screen, you would have to type the following two commands:

  who > who_output
  cat who_output

However, using the tee command, you can shorten the above process as follows:

  who | tee who_output

For more information about the tee command, see the online manual. At your Unix shell prompt, enter:

  man tee

At Indiana University, for personal or departmental Linux or Unix systems support, see Get help for Linux or Unix at IU.

This is document abys in the Knowledge Base.
Last modified on 2017-05-16 11:52:50.

Contact us

For help or to comment, email the UITS Support Center.