tee

A command that copies its standard input both to one or more files and to its standard output.

In more detail

Put it mid-pipeline to keep a snapshot of the data at that point while the pipeline carries on. -a appends instead of truncating. sudo tee is the standard way to write to a root-owned file, because in sudo echo x > file the redirect is opened by your unprivileged shell, not by sudo.

Examples

echo '127.0.0.1 staging.local' | sudo tee -a /etc/hosts
bash tests/run.sh | tee reports/report.txt

Related terms

Taught in

References