tee command tutorial in linux/unix with examples and use cases
February 4, 2020
linux tee command – read from standard input and write to standard output and files.
Copy standard input to each FILE, and also to standard output.
Syntax
tee [OPTION]... [FILE]...
Options
- -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.
MODE determines behavior with write errors on the outputs:
- 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 & Use Cases
Output to standard output and save to file
When we execute linux commands, sometimes we need to save the output to a file and print the output to standard output.
This is the tee command we can use.
➜ ping www.linuxcommands.site | tee ping.log

Output to standard output and append to file
Append output to existing file using tee command “-a” option
➜ ping www.google.com | tee -a ping.log

Output to standard output and output to multiple files
➜ ping www.google.com | tee ping.log g.log
Print stderr and stdout and save to file
Redirect stderr to stdout and use the tee command through the pipeline to save the file and print the information
➜ ./scrip.sh 2>&1 | tee output.log