TrumanWong

tee

Reads data from standard input and redirects to standard output and files.

Summary

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

The main purpose

  • Used when you need to view the data content and output it to a file at the same time.

Parameters

FILE (optional): The file to be output, which can be one or more.

Options

Long options are equivalent to short options

-a, --append Append to file instead of overwriting.
-i, --ignore-interrupts Ignore interrupt signals (Ctrl+c interrupt operation is invalid).
-p Diagnoses errors writing to non-pipelines.
--output-error[=MODE] Sets the behavior when writing errors, see the MODE section below.
--help Display help information and exit.
--version Display version information and exit.

MODE determines the output behavior when a write error occurs. The available MODEs are as follows:

'warn' Diagnose when writing to any output reports an error.
'warn-nopipe' Diagnostics when writing to any output (not a pipe) throws an error.
'exit' Exit if an error occurs when writing to any output.
'exit-nopipe' Exit with an error when writing to any output (not a pipe).

The default MODE specified for the -p option is 'warn-nopipe'.
When '--output-error' is not included in the options, the default action is to exit immediately when an error is reported when writing to the pipe, diagnose the error message and write to the non-pipeline output.

return value

The return status is success unless illegal options or illegal parameters are given.

example

# Output process information to standard output (terminal) through a pipe and overwrite it into a file.
ps -ef |tee info_a.log info_b.log

# Output the process information to the standard output (terminal) through the pipe and append it to the file.
ps -ef |tee -a info_a.log info_b.log

Notice

  1. This command is a command in the GNU coreutils package. For related help information, please see man -s 1 tee or info coreutils 'tee invocation'.
  2. There is a caching mechanism, which will be output every 1024 bytes. If input data is received from a pipe, the buffer should be full before the data is dumped to the specified file. If the file content is less than 1024 bytes, after receiving the data read from the standard input device, the buffer will be refreshed and the data will be transferred to the specified file.