Back to the command reference

tee

ShellFundamentals In simulator In real Linux

Copy input to files and to the screen

Name: tee: like a T-shaped pipe fitting (one in, two out)

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

tee copies standard input to standard output and to one or more files, like a T fitting in a pipe, so you can save data while passing it on.

A common trick: echo "..." | sudo tee /etc/somefile writes a root-owned file, because in sudo echo ... > file the redirection does not run as root.

Syntax

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

Common options

-a / --appendAppend instead of overwriting
-i / --ignore-interruptsIgnore Ctrl+C

Examples

  • $ grep ERROR logs/app.log | tee errors.txt

    Show the result and save it at the same time

    Explain
  • $ echo "done" | tee -a documents/todo.md

    Append to a file and show it

    Explain

Related