Tee (command)

1

In** computing, **** **** 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. It is primarily used in conjunction with pipes and filters. The command is named after the T-splitter used in plumbing.

Overview

The 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, DOS (e.g. 4DOS, FreeDOS), Microsoft Windows (e.g. 4NT, Windows PowerShell), and ReactOS. The Linux command was written by Mike Parker, Richard Stallman, and David MacKenzie. 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. The FreeDOS version was developed by Jim Hall and is licensed under the GPL. The tee command has also been ported to the IBM i operating system. Additionally the command offers similar capabilities.

Unix and Unix-like

tee [ -a ] [ -i ] [ File ... ] Arguments: Flags: The command returns the following exit values (exit status): 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: Flags: 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: Note: tee is implemented as a command alias. The internal cmdlet name is.

Examples

Unix and Unix-like

This displays the standard output of the command at the computer, and at the same time saves a copy of it in the file. If a file named already exists, it is deleted and replaced. Similarly, both the stdout and stderr output streams can be redirected to standard output and the using stream redirection: This displays the standard output of the command at the computer and at the same time appends a copy of it to the end of the file. If the file does not exist, it is created. 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, 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, removes common ANSI escape codes before writing to, but retains them for display.

4DOS and 4NT

This example searches the file for any lines containing the string "4DOS", makes a copy of the matching lines in , sorts the lines, and writes them to the output file :

Windows PowerShell

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

This article is derived from Wikipedia and licensed under CC BY-SA 4.0. View the original article.

Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc.
Bliptext is not affiliated with or endorsed by Wikipedia or the Wikimedia Foundation.

Edit article