The tee command
The tee command saves what flows through a pipe to a file and passes it on…
The tee command saves what flows through a pipe to a file and passes it on, so you can see output and keep a copy at the same time.
Taught in Ninja, lesson 50
A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.
Usage
tee [-a] FILE...
Save what passes through a pipe to a file, and pass it on. Copies what comes in to each FILE and to the screen (or the next command), like a T-shaped pipe fitting. Handy to save the middle of a pipeline, or to see output and keep it. Without -a it replaces the files.
How to use tee
See output and save it
ls | tee listing.txta.tmp app.log archive b.tmp backup.sh beach.jpg bin build cat.jpg data.csv diary.txt draft.txt … and 21 more lines
Save the middle of a pipeline
sort names.txt | tee sorted.txt | uniq -c 3 Ava
2 Leo
1 Mia
1 Zac
Add to a file: tee -a
echo "09:00 INFO checked" | tee -a app.log && tail -n 2 app.log09:00 INFO checked 08:15 WARN slow request 09:00 INFO checked
Options
| -a, --append | add to the end of the files instead of replacing them |
|---|
More examples
echo "backup done" | tee -a app.logbackup done
Questions about tee
Why is it called tee?
After a T-shaped pipe fitting: the input goes straight through and also out to the side, into the file.
Learn it step by step
Related commands
Every everyday command on one page, to print or keep open: the Linux commands cheat sheet.