Linux tee command

The tee command in Linux and Unix-like operating systems is used to read from standard input and write to both standard output and one or more files simultaneously. It allows you to capture and display output on the screen while saving it to a file or multiple files.

The basic syntax of the tee command is as follows:

command | tee [options] [file(s)]

Here, command represents the command or pipeline whose output you want to capture, [options] represents the various flags and parameters you can use with the tee command, and [file(s)] refers to the file or files you want to write the output to.

Some commonly used options with tee include:

  • -a: Appends the output to the specified files instead of overwriting them.
  • -i: Ignores the SIGINT signal, allowing tee to continue running even if interrupted.

To use the tee command, you can pipe the output of a command or a pipeline to tee and specify the file(s) where you want to save the output. Here are a few examples:

  1. Display the output of a command and save it to a file:
command | tee output.txt
  1. Append the output of a command to an existing file:
command | tee -a output.txt
  1. Save the output of a pipeline to multiple files:
command1 | command2 | tee file1.txt file2.txt
  1. Ignore interruptions and continue running tee:
command | tee -i output.txt

Please note that tee does not modify the input. It simply copies it to the specified file(s) and displays it on the screen. This allows you to capture and store the output of commands or pipelines while still seeing the results in real-time.

To explore additional options and information, you can refer to the tee command’s manual page by typing man tee in the terminal.