tee save a stream and pass it on

tee copies its input to one or more files while also passing it through to standard output, like a T-shaped pipe fitting. Use it to keep a copy of intermediate results without breaking a pipeline.

Availability Preinstalled on macOS, Linux and BSD

Syntax

tee [-a] file ...

Common options

OptionWhat it does
-aAppend to the file instead of overwriting it

Examples

See output and save it

make test 2>&1 | tee test.log

Append to a log

date | tee -a runs.log

Write a root-owned file

echo "127.0.0.1 dev.local" | sudo tee -a /etc/hosts

Use tee with sqx

Save a report while reading it

sqx -f users=users.csv -o md "SELECT plan, COUNT(*) AS users FROM users GROUP BY plan" | tee plans.md

Keep the raw prefetch results

Save what prefetch found, and keep a copy of it as a CSV file for later.

sqx prefetch -o csv < urls.txt | tee prefetch.csv | sqx "SELECT status_code, COUNT(*) FROM stdin GROUP BY status_code"

Full documentation

This page covers the essentials. For every option, see the official documentation:

Or read the manual in your terminal: man tee