$linuxjunkies
>

tee(1)

Read from standard input and write to standard output and files simultaneously.

UbuntuDebianFedoraArch

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

FlagWhat it does
-aappend to files instead of overwriting them
-iignore interrupt signals (SIGINT)
-pdiagnose write errors to files (ignored on most systems)
--output-error=modeset 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.txt

Write the same text to both file1.txt and file2.txt while displaying it

echo 'Hello World' | tee file1.txt file2.txt

Append log file to archive while filtering for ERROR lines on screen

cat data.log | tee -a archive.log | grep ERROR

Run a build script and save output to a timestamped log file

./build.sh | tee build_$(date +%s).log

Download a webpage, save it, and display only the first 20 lines

curl https://example.com | tee response.html | head -20

Send command1 output to command2 and command3 using process substitution

command1 | tee >(command2) | command3

Related commands