Sending output to more than one place

If you need the output of a command in more than one place, and the command does not need to run for long, the most straightforward way is to save it to a single file first, and then use cat or cp to send it wherever it needs to be copied. This is simple and easy to read and understand, and is the recommended way to do it if the command does not need to run for long.

However, for situations where you want the output to go to more than one place while the command is actually running, you can use the tee command, which copies all of its input to any files named in its arguments:

$ printf 'Copy this output\n' | tee myfile
Copy this output
$ cat myfile
Copy this output

Notice that the output went to both ...

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.