tee Copy input to a file and to the screen
Reads standard input and writes it to standard output and to one or more files at the same time. Use it to save the output of a command without losing sight of it, or to save a result partway along a pipeline.
Synopsis
COMMAND | tee [-ai] FILE...
COMMAND | tee -a FILE
Common options
| Option or form | What it does |
|---|---|
-a | Append to the file instead of overwriting it |
-i | Ignore the interrupt signal (Ctrl-C), so tee finishes writing |
FILE... | Not a flag. One or more files to write to. Several files get identical copies |
Examples
echo hello | tee out.txt
hello
echo again | tee -a out.txt
again
sort words.txt | tee sorted.txt | uniq
apple
fig
pear
ls docs | tee one.txt two.txt
old
readme.md
ls missing.txt notes.txt 2>&1 | tee result.txt
echo '127.0.0.1 test.local' | sudo tee -a /etc/hosts
Notes
- tee overwrites existing files by default. Add -a to append, or you lose what was there.
- sudo echo text > /etc/file fails because the redirect is done by your shell, not by sudo. Use echo text | sudo tee /etc/file instead. Add -a to append.
- tee sends its output to the screen too. Add > /dev/null after it, as in sudo tee file > /dev/null, to keep the screen quiet.
- tee only sees standard input. To capture a command's error messages, redirect them first with 2>&1, as in the example above.
- The exit status of a pipeline is that of its last command. If tee is last, a failure earlier in the pipeline is hidden.
See also
Last reviewed 2026-10-07.