Skip to main content

tee

The tee command reads from standard input and writes to standard output and one or more files simultaneously. It is useful for logging the output of a command while still viewing it on the terminal.

Basic Syntax

tee [OPTION]... [FILE]...

Common Options

OptionDescription
-a, --appendAppend to the given files, do not overwrite.
-i, --ignore-interruptsIgnore interrupt signals.

Real-world Examples

  1. Save command output to a file and display it:

    ls -l | tee output.txt
  2. Append to a file instead of overwriting:

    echo "New log entry" | tee -a logfile.txt
  3. Write output to multiple files:

    echo "Test" | tee file1.txt file2.txt file3.txt
  4. Use with sudo to write to a protected file:

    echo "127.0.0.1 mysite.local" | sudo tee -a /etc/hosts