Site icon LinuxCommands.site

tee command tutorial in linux/unix with examples and use cases

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

MODE determines behavior with write errors on the outputs:

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

Exit mobile version