Linux and Unix tee command

tee commandAbout tee
tee syntax
tee examples
Related commands
Linux and Unix main page

About tee

Reads from standard input, and writes to standard output and to files.


The tee command is named after the T-splitter in plumbing, which splits water into two directions and is shaped like an uppercase T.

tee copies data from standard input to each FILE, and also to standard output. In effect, tee duplicates its input, routing it to multiple outputs at once.

tee syntax

tee [OPTION]... [FILE]...


-a, --append Append to the given FILEs. Do not overwrite.
-i, --ignore-interrupts Ignore interrupt signals.
--help Display a help message, and exit.
--version Display version information, and exit.

If a FILE is specified as a dash ("-"), tee writes again to standard output.

tee examples

ls -1 *.txt | wc -l | tee count.txt

In the above example, the ls command lists all files in the current directory that have the filename extension .txt, one file per line; this output is piped to wc, which counts the lines and outputs the number; this output is piped to tee, which writes the output to the terminal, and writes the same information to the file count.txt. If count.txt already exists, it is overwritten.

cat — Output the contents of a file.