| tee | |
|---|---|
| Developers | AT&T Bell Laboratories, Mike Parker,Richard Stallman, David MacKenzie,Microware,Jim Hall,JP Software,Microsoft |
| Initial release | June 1974; 51 years ago (1974-06) |
| 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 ashellcommand that copies data fromstandard input to one or morefiles in addition tostandard output, duplicating the input to each output.[1] The name derives from thetee pipe fitting even though thetee command duplicates the input into each output instead of dividing the input into portions for each output.[2] The command is often used withpipes andfilters. Similar behaving commands are provided by many shells although syntax varies.
The command is provided inUnix andUnix-like systems,OS-9,[3]DOS (e.g.4DOS,FreeDOS),Windows (e.g.4NT,PowerShell,UnxUtils[4]),ReactOS[5] andIBM i.[6]
The Linux version was written by Mike Parker,Richard Stallman, and David MacKenzie.[7]
The FreeDOS version was developed byJim Hall and is licensed under theGPL.[8]
Additionally thesponge[9] command offers similar capabilities.
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 interruptsProcess 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 theexit status will indicate failure with a value greater than 0.
The following both displays the output of thelint program.c command and saves the output to a file namedprogram.lint; overwriting it if it already existed.
lintprogram.c|teeprogram.lintThe 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.
lintprogram.c|tee-aprogram.lintThe following bypasses a limitation of thesudo 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|sshadmin@server"sudo tee -a /root/.ssh/authorized_keys2 > /dev/null"
InBash, the output can befiltered before being written to the file—without affecting the output displayed—by usingprocess substitution. The following removes commonANSI escape codes before writing tols.txt, but retains them for display.[11]
ls--color=always|tee>(sed"s/\x1b[^m]*m//g">ls.txt)
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 overwritingWhen used with a pipe, the output of the previous command is written to atemporary file. When that command finishes,tee processes the temporary file, copying it to the file argument(s) and standard output.
This example searches the filewikipedia.txt for any lines containing the string "4DOS", makes a copy of the matching lines in4DOS.txt, sorts the lines, and writes them to the output file4DOSsorted.txt:
>find"4DOS" wikipedia.txt| tee 4DOS.txt| sort> 4DOSsorted.txt
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 acceptswildcard 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 aReadOnlycommand alias that invokes the cmdlet namedMicrosoft.PowerShell.Utility\Tee-Object.
The following displays the standard output of commandipconfig in theconsole window, and simultaneously saves a copy of it in the fileOutputFile.txt.
ipconfig|teeOutputFile.txt
The following shows that the piped input fortee can be filtered and thattee 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 fileABC.txt. To display and save all runningprocesses, filtered so that only programs starting with svc and owning more than 1000handles are output:
Get-Process|Where-Object{$_.Name-like"svc*"}|Tee-ObjectABC.txt|Where-Object{$_.Handles-gt1000}
tee: duplicate standard input – Shell and Utilities Reference,The Single UNIX Specification, Version 5 fromThe Open Grouptee(1) – Plan 9 Programmer's Manual, Volume 1tee(1) – Inferno General commandsManual