AI Hints
Home›Linux Tutorial›Errors and Combining
Linux · Lesson 53 of 120

tee

Save and see.

⏱ 2 min read▶ Video at 1:08:15🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

When you redirect into a file, you can't see the output any more. But sometimes you want both. See it on screen, and save a copy. That's what tee does.

tee
From the video: tee
  • Redirect hides the output
  • Sometimes you want both
  • tee: save and see

Tee splits the stream

Tee is named after a T shaped pipe fitting, that splits water two ways. Here, grep finds the errors, and tee writes them into errors dot log, while also printing them on the screen. And WC dash L shows the file got all seven lines too.

Terminal
grep ERROR logs/server.log | tee errors.log
2026-01-05 09:00:23 ERROR priya failed /home
2026-01-05 09:07:00 ERROR jo failed /shop
2026-01-05 09:09:18 ERROR priya failed /home
2026-01-05 09:11:08 ERROR priya failed /home
2026-01-05 09:17:21 ERROR alex failed /shop
2026-01-05 09:17:56 ERROR alex failed /home
2026-01-05 09:23:28 ERROR priya failed /cart
wc -l errors.log
7 errors.log

Useful tee options

Dash A makes tee append, instead of replacing, just like two greater than signs. And tee can sit in the middle of a pipeline, saving a snapshot of the data, while it flows on to the next command. You'll also see tee used with sudo, to write into protected system files.

keyvalue
cmd | tee filesave and show
tee -aappend
Mid-pipelinesave a snapshot
sudo teewrite system files

Summary

Tee shows output on screen, and saves it to a file, at the same time. Next, running several commands in one line.

Key takeaways
  • cmd | tee file
  • tee -a appends
  • Works mid-pipeline
Next up: Combining Commands — ; && and ||