tee(1)
Read from standard input and write to standard output and files simultaneously.
Synopsis
tee [OPTION]... [FILE]...Description
The tee command reads data from standard input, writes it to one or more files, and also sends it to standard output. This allows you to capture output in a file while still seeing it on the screen, or to duplicate data to multiple destinations in a pipeline.
tee is commonly used in pipelines after commands that don't normally write to files, letting you save intermediate results without interrupting the data flow to the next command.
Common options
| Flag | What it does |
|---|---|
-a | append to files instead of overwriting them |
-i | ignore interrupt signals (SIGINT) |
-p | diagnose write errors to files (ignored on most systems) |
--output-error=mode | set behavior on write errors: warn, exit, or warn-nopipe |
Examples
Display directory listing on screen and save it to listing.txt
ls -la | tee listing.txtWrite the same text to both file1.txt and file2.txt while displaying it
echo 'Hello World' | tee file1.txt file2.txtAppend log file to archive while filtering for ERROR lines on screen
cat data.log | tee -a archive.log | grep ERRORRun a build script and save output to a timestamped log file
./build.sh | tee build_$(date +%s).logDownload a webpage, save it, and display only the first 20 lines
curl https://example.com | tee response.html | head -20Send command1 output to command2 and command3 using process substitution
command1 | tee >(command2) | command3