Tee (command)

Tee (command)

In computing, tee is a command in various command line interpreters (shells) such as Unix shells, 4DOS/4NT and Windows PowerShell, which displays or pipes the output of a command and copies it into a file or a variable. It is primarily used in conjunction with pipes and filters.

Description and syntax

tee is normally used to "split" the output of a program so that it can be seen on the display and also be saved in a file. The command can also 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 and simultaneously copies it into the specified file(s) or variables.The syntax differs depending on the command's implementation:

Unix-like

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

Arguments:
*File One or more files that will receive the "tee-d" output.Flags:
*-a Appends the output to the end of File instead of writing over 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.

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 ouput 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] [-InputObject ] tee -Variable [-InputObject ]

Arguments:
*-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.

Note: "tee" is implemented as a ReadOnly command alias. The internal cmdlet name is Microsoft.PowerShell.UtilityTee-Object.

Examples

Unix-like

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

lint program.c | tee program.lint

This displays the standard output of the command lint program.c at the workstation, 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.

* To view and save 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 workstation 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:

echo "Body of file..." | sudo tee root_owned_file > /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.

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:

c:> 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 outputted:

gps | where { $_.Name -like "svc*" } | tee ABC.txt | where { $_.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.

ee also

*Pipeline (Unix)
*List of Unix programs
*A FAQ on Linux I/O Redirection [http://www.cpqlinux.com/redirect.html "Linux I/O Redirection"] with tee

References

*man|cu|tee|SUS|duplicate standard input


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Tee (disambiguation) — Tee is a three letter abbreviation with multiple meanings, including: * T, a letter of the alphabet * Tee, an item of sports equipment, used a.o. in golf. * Tee, part of a golf course from where each golfer plays his first shot at each hole. * T… …   Wikipedia

  • tee (Unix) — tee est une commande POSIX qui permet de lire depuis l entrée standard et écrire sur la sortie standard tout en écrivant dans des fichiers. Elle est notamment utile dans des tubes pour relayer la sortie à une nouvelle commande tout en la… …   Wikipédia en Français

  • tee — Применение команды tee: Результат команды ls пересылается в tee, который копирует его в файл file.txt и в команду less. Название tee происходит от схожести между схематическим отображением работы команды и заглавной буквой …   Википедия

  • Command prompt — Interface en ligne de commande Une interface en ligne de commande est une interface homme machine dans laquelle la communication entre l utilisateur et l ordinateur s effectue en mode texte : l utilisateur tape du texte au clavier pour… …   Wikipédia en Français

  • Microsoft Command Shell — Windows PowerShell Screenshot von PowerShell 1.0 Basisdaten Entwickler: Microsoft Corporation Aktuelle Version …   Deutsch Wikipedia

  • System Center Operations Manager Command Shell — Windows PowerShell Screenshot von PowerShell 1.0 Basisdaten Entwickler: Microsoft Corporation Aktuelle Version …   Deutsch Wikipedia

  • cd (command) — cd, sometimes also available as chdir (change directory), is a command line command to change the current working directory in operating systems such as Unix, DOS, OS/2, AmigaOS (where if a bare path is given, cd is implied), Windows, and Linux.… …   Wikipedia

  • more (command) — more Example output of the more command Developer(s) Daniel Halbert Operating system Cross platform …   Wikipedia

  • Whoami (command) — whoami whoami (Who am I signifiant qui je suis ) est une commande UNIX permettant d afficher le nom de l usager associé à l identificateur effectif (user ID ou UID) courant de l usager. Commandes Unix Aide arch · apropos · cal ·… …   Wikipédia en Français

  • Pipeline (Unix) — In Unix like computer operating systems, a pipeline is the original software pipeline : a set of processes chained by their standard streams, so that the output of each process ( stdout ) feeds directly as input ( stdin ) of the next one. Each… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”