Linux – tee Command

The tee command is used to read from standard input and write to both standard output and files simultaneously. This allows you to view the output of a command while also saving it to a file. It is commonly used in conjunction with other commands in pipelines.

Initial Example

Using tee to save the output of a command to a file while still displaying it on the terminal:

Tutorials dojo strip
UNIX

TEE Parameters

ParameterDescription
-a, --appendAppend the output to the specified files instead of overwriting them.
-i, --ignore-interruptsIgnore interrupt signals during execution.
-pOperate in a more suitable mode when handling pipes.
--output-error[=MODE]Define behavior upon encountering a write error. Options include warn, warn-nopipe, exit, exit-nopipe.
--helpDisplay help information and exit.
--versionShow version information and exit.

Examples

1. Basic Usage

To display the output and save it to a file:

UNIX

2. Append to a File

To append the output to a file instead of overwriting it, use the -a option:

UNIX

3. Using tee with Pipes

To use tee in a pipeline, saving intermediate output to a file while passing it to the next command:

UNIX

4. Writing to Multiple Files

To write the output to multiple files simultaneously:

UNIX

5. Combining tee with sudo

To write to a file that requires elevated permissions, combine tee with sudo:

UNIX

Linux Playground

Tutorials dojo strip
Scroll to Top