HxHippy

tee

Read from standard input and write to standard output and files

Overview

The `tee` command copies standard input to standard output, making a copy in zero or more files. The output is unbuffered.

Syntax

tee [OPTION]... [FILE]...

Common Options

-a, --append

Append to the given FILEs, do not overwrite.

-i, --ignore-interrupts

Ignore interrupt signals (like Ctrl+C).

-p

Diagnose errors writing to non-pipeline outputs.

--output-error[=MODE]

Set behavior on write error. MODE can be: warn (default), warn-nopipe, exit, exit-nopipe.

--help

Display help and exit.

--version

Output version information and exit.

Examples

$ ls -l | tee directory_listing.txt

Displays the long listing of files and simultaneously saves it to `directory_listing.txt`.

$ echo "Important log message" | tee -a application.log

Appends the message to `application.log` and prints it to the terminal.

$ cat script.sh | tee script.backup.sh | sh

Duplicates `script.sh` to `script.backup.sh` and then executes the original script content passed through `tee`.

$ date | tee -a current_time.txt log_file.txt

Appends the current date and time to both `current_time.txt` and `log_file.txt`, and also displays it.

$ some_command 2>&1 | tee output_and_errors.log

Redirects both stdout and stderr of `some_command` to `tee`, which then writes to `output_and_errors.log` and stdout.

teeredirectoutputfilepipeduplicatestdoutlog