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
| Option | Description |
|---|---|
-a, --append | Append to the given files, do not overwrite. |
-i, --ignore-interrupts | Ignore interrupt signals. |
Real-world Examples
-
Save command output to a file and display it:
ls -l | tee output.txt -
Append to a file instead of overwriting:
echo "New log entry" | tee -a logfile.txt -
Write output to multiple files:
echo "Test" | tee file1.txt file2.txt file3.txt -
Use with
sudoto write to a protected file:echo "127.0.0.1 mysite.local" | sudo tee -a /etc/hosts