tee on Linux solves a common problem: you want to see command output live and save it for a ticket or post-mortem. Unlike shell redirection alone, tee copies the stream to one or more files while still printing to the terminal.
See: cron logging wrapper,
journalctl,
tail -f.
Basic tee
Overwrite the log file each run unless you pass -a to append.
bashsave and show
./deploy.sh 2>&1 | tee /var/log/deploy.log

Append mode
Long-running maintenance jobs should append with timestamps in the script header.
bashappend
apt upgrade -y 2>&1 | tee -a /var/log/apt-upgrade.log

sudo tee
Redirecting to /etc with > fails under sudo — pipe through tee instead.
bashwrite config
echo 'net.ipv4.ip_forward=1' | sudo tee /etc/sysctl.d/99-forward.conf

Multiple files
tee can write to several destinations — handy for local log plus NFS mirror.
WarningLog files under
/var/log may need root ownership — create them with correct permissions first.
Quick Reference
cmd | tee file.log- Append:
tee -a - Protected paths:
| sudo tee path
Related tutorials
Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.