The tee command in Linux is used to read from standard input and write to standard output and one or more files simultaneously. This allows you to view command output in the terminal while also saving it to a file. It's particularly useful for logging and monitoring purposes.
Basic Usage
command | tee output.txt
This command will execute command, display the output in the terminal, and save it to output.txt.
Appending Output
To append output to an existing file, use the -a option:
command | tee -a output.txt
Redirecting Standard Error
You can also capture both standard output and standard error:
command 2>&1 | tee output.txt
This makes tee a powerful tool for managing output in Linux environments.
