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 At IU, how do I get support for Linux or Unix?

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

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.