tee
Quick Reference
Command Name:
tee
Category:
utilities
Platform:
linux
Basic Usage:
Common Use Cases
- 1
Text redirection
Redirect output to both the console and files
- 2
Logging
Capture output for logging and debugging
- 3
Scripting
Use in shell scripts to redirect output programmatically
- 4
Data processing
Manipulate and transform text data
Syntax
tee [OPTION]... [FILE]...
Options
Option | Description |
---|---|
-a, --append | Append to the given files, do not overwrite |
-i, --ignore-interrupts | Ignore interrupt signals |
-p | Diagnose errors writing to non pipes |
--output-error[=MODE] | Set behavior on write error. See MODE below |
--help | Display help information |
--version | Display version information |
MODE values for --output-error:
Mode | Description |
---|---|
warn | Diagnose errors writing to any output |
warn-nopipe | Diagnose errors writing to any output not a pipe |
exit | Exit on error writing to any output |
exit-nopipe | Exit on error writing to any output not a pipe |
Examples
How to Use These Examples
The examples below show common ways to use the tee
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
echo "Hello, World!" | tee file.txt
Write "Hello, World!" to both the terminal and file.txt.
ls -la | tee directory_listing.txt
Display directory listing and save it to a file.
command | tee -a logfile.txt
Append command output to an existing file while also displaying it.
Advanced Examples:
command | tee file1.txt file2.txt file3.txt
Write output to multiple files simultaneously.
command 2>&1 | tee output.log
Capture both standard output and error messages.
make 2>&1 | tee build.log | grep "warning:"
Save full compilation output to a file while only displaying warnings in the terminal.