tee in Linux: write to a file and the screen at once
Updated July 3, 2026
tee writes what passes through a pipe both to a file and to the screen at once.
Syntax
... | tee fileCommon cases
ls -l | tee out.txt # show and save
make 2>&1 | tee build.log # watch the build and record a log
ls | tee a.txt b.txt # to several files at once
echo on | sudo tee /sys/file # write to a root-owned file in a pipe
ls | tee -a out.txt # -a append instead of overwriteHow it works: a T-joint in the pipe
The name
teecomes from a plumbing T-joint: the stream comes in and splits two ways. Withoutteeyou have to choose: either> file(output goes to the file, the screen is empty) or watch the screen (nothing is saved).teedoes both at once. A common trick issudo tee: writingsudo command > /filemakes your shell do the redirect, and the shell has no root rights, so it fails; whilecommand | sudo tee /filewrites to the file as root. The-aflag appends, like>>.
In the book
This topic is covered in full in the chapter Streams, redirection, pipelines.
See also
Redirection > and >>, Pipes and filters.
Try it
Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand - the container is deleted when you leave.