tee (command)
{{short description|Shell command that copies standard input to standard output and to one or more files}}
{{lowercase}}
{{Infobox software
| name = tee
| logo =
| screenshot =
| screenshot size =
| caption =
| developer = AT&T Bell Laboratories, Mike Parker, Richard Stallman, David MacKenzie, Microware, Jim Hall, JP Software, Microsoft
| released = {{Start date and age|1974|6}}
| latest release version =
| latest release date =
| programming language = C
| operating system = Unix, Unix-like, Plan 9, Inferno, OS-9, FreeDOS, Windows, ReactOS, IBM i
| platform = Cross-platform
| genre = Command
| license = FreeDOS: GPL-2.0-or-later
ReactOS: GPLv2
Plan 9: MIT License
| website =
}}
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.{{cite web | url=http://www.unix.com/man-page/POSIX/1/tee/ | title=Man Page for tee (posix Section 1) | publisher=IEEE Std 1003.1, 2003 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6 | access-date=1 December 2013}} The name derives from the tee pipe fitting even though the {{code|tee}} command duplicates the input into each output instead of dividing the input into portions for each output.{{cite web
| url = http://kb.iu.edu/data/abnd.html
| title = In Unix, what do some obscurely named commands stand for?
| access-date = 2012-02-03
| archive-date = 27 November 2005
| archive-url = https://web.archive.org/web/20051127090549/http://kb.iu.edu/data/abnd.html
| url-status = dead
}} 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,{{cite book|author=Paul S. Dayan|year=1992|title=The OS-9 Guru - 1 : The Facts|publisher=Galactic Industrial Limited|isbn=0-9519228-0-7}} DOS (e.g. 4DOS, FreeDOS), Windows (e.g. 4NT, PowerShell, UnxUtils{{Cite web|url=http://unxutils.sourceforge.net/|title=Native Win32 ports of some GNU utilities|website=unxutils.sourceforge.net}}), ReactOS{{Cite web|url=https://github.com/reactos/reactos|title=reactos/reactos|website=GitHub|date=3 January 2022}} and IBM i.{{cite web |title=IBM System i Version 7.2 Programming Qshell |language=en |author=IBM |website=IBM |author-link=IBM |url=https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |access-date=2020-09-05 }}
The Linux version was written by Mike Parker, Richard Stallman, and David MacKenzie.{{Cite web|url=https://www.mankier.com/1/tee#Author|title=tee: read from standard input and write to standard output and files|website=www.mankier.com}}
The FreeDOS version was developed by Jim Hall and is licensed under the GPL.{{Cite web|url=http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/tee.html|title=ibiblio.org FreeDOS Package -- tee (Unix-like)|website=www.ibiblio.org}}
Additionally the sponge
{{Cite web|url=https://linux.die.net/man/1/sponge|title=sponge(1): soak up stdin/write to file - Linux man page|website=linux.die.net}} command offers similar capabilities.
Unix
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.[https://www.gnu.org/software/coreutils/manual/html_node/tee-invocation.html GNU Coreutils, tee invocation].
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=
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.{{cite web|title=GNU Coreutils: tee invocation|url=https://www.gnu.org/software/coreutils/manual/html_node/tee-invocation.html#index-_002d_002doutput_002derror|access-date=3 February 2016}}
ls --color=always | tee >(sed "s/\x1b[^m]*m//g" > ls.txt)
4DOS and 4NT
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, {{code|tee}} processes the temporary file; copying it to the file argument(s) and standard output.
=Examples=
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
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]
tee -Variable
-InputObject
Specifies the object input to the cmdlet. The parameter accepts variables that contain the objects and commands or expression that return the objects.-FilePath
Specifies the file where the cmdlet stores the object. The parameter accepts wildcard characters that resolve to a single file.-Variable
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=
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
- {{Annotated link|GNU Core Utilities}}
- {{Annotated link|List of POSIX commands}}
- {{Annotated link|syslog}}
References
{{Reflist}}
Further reading
- {{Cite book|author-last=McElhearn|author-first=Kirk|title=The Mac OS X Command Line: Unix Under the Hood|date=2006|publisher=John Wiley & Sons|isbn=978-0470113851}}
External links
{{Wikibooks|Guide to Unix|Commands}}
- An introduction on Linux I/O Redirection [http://wadhavankar.org/tn/linux/user/standardIo.php "Linux I/O Redirection"] {{Webarchive|url=https://web.archive.org/web/20120610042438/http://wadhavankar.org/tn/linux/user/standardIo.php |date=10 June 2012 }} with tee
- [https://www.gnu.org/software/coreutils/manual/html_node/tee-invocation.html GNU tee manual]
- {{man|cu|tee|SUS|duplicate standard input}}
- {{man|1|tee|Plan 9}}
- {{man|1|tee|Inferno}}
- [https://github.com/tothpaul/Delphi-Tee Delphi-Tee] - Delphi (software) OpenSource implementation
{{Unix commands}}
{{Plan 9 commands}}
{{Core Utilities commands}}
{{Windows commands}}
{{Use dmy dates|date=March 2018}}
Category:Unix text processing utilities
Category:Unix SUS2008 utilities
Category:Inferno (operating system) commands
Category:IBM i Qshell commands