← Back to Bash Course | Chapter 3: Control Flow | Lesson 11 of 14

tee

In this page:

  1. tee

tee

tee reads from standard input and writes it both to a file and back out to standard output simultaneously, letting you save output to a log while still seeing it in your terminal. It's often placed in the middle of a pipeline. tee -a appends to the file instead of overwriting it.

Note: Use command | tee log.txt to view output live while also saving it for later.

Example: tee

bash
#!/bin/bash
echo "Important message" | tee log.txt
echo "--- contents of log.txt ---"
cat log.txt

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.