Tee (command)

Short description: Standard UNIX utility

teeDeveloper(s)| AT&T Bell Laboratories, Mike Parker, Richard Stallman, David MacKenzie, Microware, Jim Hall, JP Software, Microsoft

|

Initial release| June 1974; 52 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

In computing, `tee` is a command in command-line interpreters (shells) using standard streams which reads standard input and writes it to both standard output and one or more files, effectively duplicating its input.[1] It is primarily used in conjunction with pipes and filters. The command is named after the T-splitter used in plumbing.[2]

## Contents

* 1 Overview
* 2 Implementations
* 2.1 Unix and Unix-like
* 2.2 4DOS and 4NT
* 2.3 Windows PowerShell
* 3 Examples
* 3.1 Unix and Unix-like
* 3.2 4DOS and 4NT
* 3.3 Windows PowerShell
* 4 See also
* 5 References
* 6 Further reading
* 7 External links

## Overview

Example usage of tee: The output of `ls -l` is redirected to tee which copies them to the file file.txt and to the pager `less`. The name tee comes from this scheme - it looks like the capital letter T

The `tee` command is normally used to split the output of a program so that it can be both displayed and saved in a file. The command can be used to capture intermediate output before the data is altered by another command or program. The tee command reads standard input, then writes its content to standard output. It simultaneously copies the data into the specified file(s) or variables. The syntax differs depending on the command's implementation.

## Implementations

The command is available for Unix and Unix-like operating systems, Microware OS-9,[3] DOS (e.g. 4DOS, FreeDOS), Microsoft Windows (e.g. 4NT, Windows PowerShell), and ReactOS.[4] The Linux `tee` command was written by Mike Parker, Richard Stallman, and David MacKenzie.[5] The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.[6] The FreeDOS version was developed by Jim Hall and is licensed under the GPL.[7] The tee command has also been ported to the IBM i operating system.[8]

Additionally the `sponge`[9] command offers similar capabilities.

### Unix and Unix-like

tee [ -a ] [ -i ] [ File ... ]

Arguments:

* `File ...` A list of files, each of which receives the output.

Flags:

* `-a` Appends the output to each file, rather than overwriting it.
* `-i` Ignores interrupts.

The command returns the following exit values (exit status):

* 0 The standard input was successfully copied to all output files.
* >0 An error occurred.

Using process substitution lets more than one process read the standard output of the originating process. Read this example from GNU Coreutils, tee invocation.

Note: If a write to any successfully opened File operand is not successful, writes to other successfully opened File operands and standard output will continue, but the exit value will be >0\.

### 4DOS and 4NT

TEE [/A] file...

Arguments:

* `file` One or more files that will receive the "tee'd" output.

Flags:

* `/A` Append the pipeline content to the output file(s) rather than overwriting them.

Note: When tee is used with a pipe, the output of the previous command is written to a temporary file. When that command finishes, tee reads the temporary file, displays the output, and writes it to the file(s) given as command-line argument.

### Windows PowerShell

tee [-FilePath] <String> [-InputObject <PSObject>]
tee -Variable <String> [-InputObject <PSObject>]

Arguments:

* `-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.

Note: tee is implemented as a `ReadOnly` command alias. The internal cmdlet name is `Microsoft.PowerShell.Utility\Tee-Object`.

## Examples

### Unix and Unix-like

* To view and save the output from a command (lint) at the same time:

lint program.c | tee program.lint

This displays the standard output of the command `lint program.c` at the computer, and at the same time saves a copy of it in the file `program.lint`. If a file named `program.lint` already exists, it is deleted and replaced.

Similarly, both the stdout and stderr output streams can be redirected to standard output and the `program.lint` using stream redirection:

lint program.c 2>&1 | tee program.lint

* To view and append the output from a command to an existing file:

lint program.c | tee -a program.lint

This displays the standard output of the `lint program.c` command at the computer and at the same time appends a copy of it to the end of the `program.lint` file. If the `program.lint` file does not exist, it is created.

* To allow escalation of permissions:

cat ~/.ssh/id_rsa.pub | ssh admin@server "sudo tee -a /root/.ssh/authorized_keys2 > /dev/null"

This example shows tee being used to bypass an inherent limitation in the sudo command. sudo is unable to pipe the standard output to a file. By dumping its stdout stream into `/dev/null`, we also suppress the mirrored output in the console. The command above 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.

In Bash, the output can be filtered before being written to the file—without affecting the output displayed—by using process substitution. For example,

ls --color=always | tee >(sed "s/\x1b[^m]*m//g" > ls.txt)

removes common ANSI escape codes before writing to `ls.txt`, but retains them for display.[10]

### 4DOS and 4NT

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

### Windows PowerShell

* To view and save the output from a command at the same time:

ipconfig | tee OutputFile.txt

This displays the standard output of the command `ipconfig` at the console window, and simultaneously saves a copy of it in the file `OutputFile.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 }

This example 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`.

* Windows Powershell is not suitable for binary and raw data and will always treat the stream as text and will modify the data as it is transferred.

## See also

* GNU Core Utilities
* Pipeline (Unix)
* List of Unix commands
* Logger

## References

1. ↑ "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. http://www.unix.com/man-page/POSIX/1/tee/.
2. ↑ "In Unix, what do some obscurely named commands stand for?". http://kb.iu.edu/data/abnd.html.
3. ↑ Paul S. Dayan (1992). The OS-9 Guru - 1 : The Facts. Galactic Industrial Limited. ISBN 0-9519228-0-7.
4. ↑ "reactos/reactos". 3 January 2022. https://github.com/reactos/reactos.
5. ↑ "tee: read from standard input and write to standard output and files". https://www.mankier.com/1/tee#Author.
6. ↑ "Native Win32 ports of some GNU utilities". http://unxutils.sourceforge.net/.
7. ↑ "ibiblio.org FreeDOS Package -- tee (Unix-like)". http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/tee.html.
8. ↑ IBM. "IBM System i Version 7.2 Programming Qshell" (in en). https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc.
9. ↑ "sponge(1): soak up stdin/write to file - Linux man page". https://linux.die.net/man/1/sponge.
10. ↑ "GNU Coreutils: tee invocation". https://www.gnu.org/software/coreutils/manual/html_node/tee-invocation.html#index-_002d_002doutput_002derror.

## Further reading

* The Mac OS X Command Line: Unix Under the Hood. John Wiley & Sons. 2006. ISBN 978-0470113851.

## External links

* An introduction on Linux I/O Redirection "Linux I/O Redirection" with tee
* GNU tee manual
* `tee`: duplicate standard input – Commands & Utilities Reference, The Single UNIX Specification, Issue 7 from The Open Group
* `tee(1)` – Plan 9 Programmer's Manual, Volume 1
* `tee(1)` – Inferno General commands Manual
* Delphi-Tee \- Delphi OpenSource implementation

* v
* t
* e

Unix command-line interface programs and shell builtins

File system|

* cat
* chmod
* chown
* chgrp
* cksum
* cmp
* cp
* dd
* du
* df
* file
* fuser
* ln
* ls
* mkdir
* mv
* pax
* pwd
* rm
* rmdir
* split
* tee
* touch
* type
* umask

Processes|

* at
* bg
* crontab
* fg
* kill
* nice
* ps
* time

User environment|

* env
* exit
* logname
* mesg
* talk
* tput
* uname
* who
* write

Text processing|

* awk
* basename
* comm
* csplit
* cut
* diff
* dirname
* ed
* ex
* fold
* head
* iconv
* join
* m4
* more
* nl
* paste
* patch
* printf
* sed
* sort
* strings
* tail
* tr
* uniq
* vi
* wc
* xargs

Shell builtins|

* alias
* cd
* echo
* test
* unset
* wait

Searching|

* find
* grep

Documentation|

* man

Software development|

* ar
* ctags
* lex
* make
* nm
* strip
* yacc

Miscellaneous|

* bc
* cal
* expr
* lp
* od
* sleep
* true and false

* Categories
* Standard Unix programs
* Unix SUS2008 utilities
* List

* v
* t
* e

Windows command-line programs and shell builtins

* COMMAND.COM
* Command Prompt
* Windows PowerShell
* Recovery Console

File system navigation|

* cd (chdir)
* dir
* popd
* pushd
* tree

File management|

* attrib
* cacls
* cipher
* compact
* copy
* del (erase)
* deltree
* expand
* icacls
* makecab
* mkdir (md)
* mklink
* move
* recover
* ren (rename)
* replace
* rmdir (rd)
* robocopy
* tar
* xcopy

Disk management|

* chkdsk
* convert
* defrag
* diskcomp
* diskcopy
* diskpart
* drvspace
* fdisk
* format
* label
* manage-bde
* subst
* scandisk
* sys
* vol
* vssadmin

Processes|

* at
* exit
* kill
* powercfg
* runas
* sc
* schtasks
* shutdown
* start
* taskkill
* tasklist

Registry|

* assoc
* ftype
* reg
* regini
* regsvr32

User environment|

* date
* mode
* path
* set
* setx
* time
* title
* ver
* whoami

File contents|

* comp
* edit
* edlin
* fc
* find
* findstr
* print
* type

Scripting|

* choice
* clip
* cscript
* doskey
* echo
* for
* forfiles
* goto
* if
* more
* pause
* prompt
* rem
* timeout

Networking|

* arp
* BITSAdmin
* cURL
* getmac
* hostname
* ipconfig
* net
* netsh
* netstat
* nslookup
* PathPing
* ping
* route
* scp
* sftp
* ssh
* ssh-add
* ssh-agent
* ssh-keygen
* ssh-keyscan
* tracert
* winrm
* winrs

Maintenance and care|

* driverquery
* eventcreate
* eventtriggers
* msiexec
* ntbackup
* sfc
* systeminfo
* w32tm
* WBAdmin
* winsat
* wmic

Boot management|

* bcdedit
* bootcfg
* fixboot
* fixmbr

Software development|

* debug
* exe2bin
* QBasic

Miscellaneous|

* cls
* dism
* dpath
* gpupdate
* help
* MSCDEX
* pentnt
* wsl

* List of DOS commands
* Environment variables

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Tee (command). Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Software:Tee_(command)&oldid=688291"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template