tee
TLDR
Write stdin to file and stdout
SYNOPSIS
tee [options] [file...]
DESCRIPTION
tee reads from standard input and writes to both standard output and one or more files simultaneously. Named after the T-shaped pipe fitting in plumbing, it "splits" the data stream.
Common uses include logging command output while still viewing it, saving intermediate pipeline results for debugging, and writing to files requiring elevated privileges via sudo.
Without -a, tee overwrites existing files. With multiple files, the same content is written to all of them.
Tee continues the pipelineāoutput goes to both files and stdout, allowing further processing with additional pipe stages.
PARAMETERS
-a, --append
Append to files instead of overwriting-i, --ignore-interrupts
Ignore SIGINT (interrupt signal)-p
Diagnose errors writing to non-pipes--output-error[=mode]
Set behavior on write error (warn, warn-nopipe, exit, exit-nopipe)--help
Display help and exit--version
Display version and exit
CAVEATS
For writing to protected files with sudo, use sudo tee rather than sudo echo > because redirection happens in the current shell before sudo.
In pipelines with set -o pipefail, tee failures can go unnoticed. Use --output-error=exit for strict error handling.
When combined with commands that buffer output, you may not see immediate results. Use stdbuf or command-specific unbuffering options if needed.


