Read from stdin and write to stdout and files.
The tee command reads from standard input and writes to both standard output and one or more files simultaneously. It is named after the T-splitter in plumbing.
By default, tee overwrites the specified files. The -a option appends to the files instead of overwriting them. This makes tee invaluable in pipelines where you want to save intermediate output while still passing it through to the next command.
tee is commonly used to log the output of a pipeline to a file while still displaying it on the terminal, or to send data to multiple destinations at once.
| Name | Description | Optional |
|---|---|---|
file |
One or more files to write to in addition to stdout. | No |
-a |
Append to the given files rather than overwriting them. | Yes |
echo 'log entry' | tee log.txt
ls -l | tee listing.txt | wc -l
command 2>&1 | tee -a debug.log