tee (command)
Developer(s) | AT&T Bell Laboratories, Mike Parker, Richard Stallman, David MacKenzie, Microware, Jim Hall, JP Software, Microsoft |
---|---|
Initial release | June 1974 |
Written in | C |
Operating system | Unix, Unix-like, Plan 9, Inferno, OS-9, FreeDOS, Windows, ReactOS, IBM i |
Platform | Cross-platform |
Type | Command |
License | FreeDOS: GPL-2.0-or-later ReactOS: GPLv2 Plan 9: MIT License |

tee
is shell command that copies data from standard input to one or more files in addition to standard output; duplicating the input to each output.[1] The name derives from the tee pipe fitting even though the tee
command duplicates the input into each output instead of dividing the input into portions for each output.[2] The command is often used with pipes and filters. Similar behaving commands are provided by many shells although syntax varies.

The command is provided in Unix and Unix-like systems, OS-9,[3] DOS (e.g. 4DOS, FreeDOS), Windows (e.g. 4NT, PowerShell, UnxUtils[4]), ReactOS[5] and IBM i.[6]

The Linux version was written by Mike Parker, Richard Stallman, and David MacKenzie.[7]
The FreeDOS version was developed by Jim Hall and is licensed under the GPL.[8]
Additionally the sponge
[9] command offers similar capabilities.
Unix
[edit]The typical syntax on a Unix-based system can be described as:
tee [-a] [-i] [file...]
file...
One or more names for files to receive the command input data-a
Append to a file rather than overwriting-i
Ignore interrupts
Process substitution lets more than one process read the standard output of the originating process.[10].
If a write to any file is not successful, writes to other files and standard output continue, but the exit status will indicate failure with a value greater than 0.
Examples
[edit]The following both displays the output of the lint program.c
command and saves the output to a file named program.lint
; overwriting it if it already existed.
lint program.c | tee program.lint
The following does the same as the previous example, except for appending the output to an existing file instead of overwriting it. The file is created if it was not pre-existing.
lint program.c | tee -a program.lint
The following bypasses a limitation of the sudo
command which is unable to pipe standard output to a file. By dumping its stdout stream into /dev/null
, output to the console suppressed. This gives the current user root access to a server over ssh, by installing the user's public key to the server's key authorization list.
cat ~/.ssh/id_rsa.pub | ssh admin@server "sudo tee -a /root/.ssh/authorized_keys2 > /dev/null"
In Bash, the output can be filtered before being written to the file—without affecting the output displayed—by using process substitution. The following removes common ANSI escape codes before writing to ls.txt
, but retains them for display.[11]
ls --color=always | tee >(sed "s/\x1b[^m]*m//g" > ls.txt)
4DOS and 4NT
[edit]The syntax on 4DOS and 4NT can be described as:
TEE [/A] file...
file
One or more names for files to receive the command input data/A
Append to a file rather than overwriting
When used with a pipe, the output of the previous command is written to a temporary file. When that command finishes, tee
processes the temporary file; copying it to the file argument(s) and standard output.
Examples
[edit]This example searches the file wikipedia.txt
for any lines containing the string "4DOS", makes a copy of the matching lines in 4DOS.txt
, sorts the lines, and writes them to the output file 4DOSsorted.txt
:
>find "4DOS" wikipedia.txt | tee 4DOS.txt | sort > 4DOSsorted.txt
PowerShell
[edit]Powershell is not suitable for binary and raw data, always treats the stream as text, and modifies the data as it is transferred.
The syntax on PowerShell can be described as:
tee [-FilePath] <String> [-InputObject <PSObject>] tee -Variable <String> [-InputObject <PSObject>]
-InputObject <PSObject>
Specifies the object input to the cmdlet. The parameter accepts variables that contain the objects and commands or expression that return the objects.-FilePath <String>
Specifies the file where the cmdlet stores the object. The parameter accepts wildcard characters that resolve to a single file.-Variable <String>
A reference to the input objects will be assigned to the specified variable.
The command is implemented as a ReadOnly
command alias that invokes the cmdlet named Microsoft.PowerShell.Utility\Tee-Object
.
Examples
[edit]The following displays the standard output of command ipconfig
in the console window, and simultaneously saves a copy of it in the file OutputFile.txt
.
ipconfig | tee OutputFile.txt
The following shows that the piped input for tee can be filtered and that tee is used to display that output, which is filtered again so that only processes owning more than 1000 handles are displayed, and writes the unfiltered output to the file ABC.txt
. To display and save all running processes, filtered so that only programs starting with svc and owning more than 1000 handles are output:
Get-Process | Where-Object { $_.Name -like "svc*" } | Tee-Object ABC.txt | Where-Object { $_.Handles -gt 1000 }
See also
[edit]- GNU Core Utilities – Collection of standard, Unix-based utilities from GNU
- List of POSIX commands
- syslog – Network event logging system and protocol
References
[edit]- ^ "Man Page for tee (posix Section 1)". IEEE Std 1003.1, 2003 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6. Retrieved 1 December 2013.
- ^ "In Unix, what do some obscurely named commands stand for?". Archived from the original on 27 November 2005. Retrieved 3 February 2012.
- ^ Paul S. Dayan (1992). The OS-9 Guru - 1 : The Facts. Galactic Industrial Limited. ISBN 0-9519228-0-7.
- ^ "Native Win32 ports of some GNU utilities". unxutils.sourceforge.net.
- ^ "reactos/reactos". GitHub. 3 January 2022.
- ^ IBM. "IBM System i Version 7.2 Programming Qshell" (PDF). IBM. Retrieved 5 September 2020.
- ^ "tee: read from standard input and write to standard output and files". www.mankier.com.
- ^ "ibiblio.org FreeDOS Package -- tee (Unix-like)". www.ibiblio.org.
- ^ "sponge(1): soak up stdin/write to file - Linux man page". linux.die.net.
- ^ GNU Coreutils, tee invocation
- ^ "GNU Coreutils: tee invocation". Retrieved 3 February 2016.
Further reading
[edit]- McElhearn, Kirk (2006). The Mac OS X Command Line: Unix Under the Hood. John Wiley & Sons. ISBN 978-0470113851.
External links
[edit]- An introduction on Linux I/O Redirection "Linux I/O Redirection" Archived 10 June 2012 at the Wayback Machine with tee
- GNU tee manual
- The Single UNIX Specification, Version 5 from The Open Group : duplicate standard input – Shell and Utilities Reference,
- Plan 9 Programmer's Manual, Volume 1 –
- Inferno General commands Manual –
- Delphi-Tee - Delphi (software) OpenSource implementation