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]
tee
ls -l
less
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.
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.
sponge
tee [ -a ] [ -i ] [ File ... ]
Arguments:
File ...
Flags:
-a
-i
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.
TEE [/A] file...
file
/A
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.
tee [-FilePath] <String> [-InputObject <PSObject>] tee -Variable <String> [-InputObject <PSObject>]
-InputObject <PSObject>
-FilePath <String>
-Variable <String>
Note: tee is implemented as a ReadOnly command alias. The internal cmdlet name is Microsoft.PowerShell.Utility\Tee-Object.
ReadOnly
Microsoft.PowerShell.Utility\Tee-Object
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.
lint program.c
program.lint
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
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.
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.
/dev/null
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]
ls.txt
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:
wikipedia.txt
4DOS.txt
4DOSsorted.txt
>find "4DOS" wikipedia.txt | tee 4DOS.txt | sort > 4DOSsorted.txt
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.
ipconfig
OutputFile.txt
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.
ABC.txt
tee(1)
Lokasi Pengunjung: 3.144.230.33