Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

tee (command)

From Wikipedia, the free encyclopedia
Shell command that copies standard input to standard output and to one or more files
tee
DevelopersAT&T Bell Laboratories, Mike Parker,Richard Stallman, David MacKenzie,Microware,Jim Hall,JP Software,Microsoft
Initial releaseJune 1974; 51 years ago (1974-06)
Written inC
Operating systemUnix,Unix-like,Plan 9,Inferno,OS-9,FreeDOS,Windows,ReactOS,IBM i
PlatformCross-platform
TypeCommand
LicenseFreeDOS:GPL-2.0-or-later
ReactOS:GPLv2
Plan 9:MIT License

tee is ashellcommand that copies data fromstandard input to one or morefiles in addition tostandard output, duplicating the input to each output.[1] The name derives from thetee pipe fitting even though thetee command duplicates the input into each output instead of dividing the input into portions for each output.[2] The command is often used withpipes andfilters. Similar behaving commands are provided by many shells although syntax varies.

The command is provided inUnix andUnix-like systems,OS-9,[3]DOS (e.g.4DOS,FreeDOS),Windows (e.g.4NT,PowerShell,UnxUtils[4]),ReactOS[5] andIBM i.[6]

The Linux version was written by Mike Parker,Richard Stallman, and David MacKenzie.[7]

The FreeDOS version was developed byJim Hall and is licensed under theGPL.[8]

Additionally thesponge[9] command offers similar capabilities.

Unix

[edit]

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.[10]

If a write to any file is not successful, writes to other files and standard output continue, but theexit status will indicate failure with a value greater than 0.

Examples

[edit]

The following both displays the output of thelint program.c command and saves the output to a file namedprogram.lint; overwriting it if it already existed.

lintprogram.c|teeprogram.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.

lintprogram.c|tee-aprogram.lint

The following bypasses a limitation of thesudo 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|sshadmin@server"sudo tee -a /root/.ssh/authorized_keys2 > /dev/null"

InBash, the output can befiltered before being written to the file—without affecting the output displayed—by usingprocess substitution. The following removes commonANSI escape codes before writing tols.txt, but retains them for display.[11]

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

4DOS and 4NT

[edit]

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 atemporary file. When that command finishes,tee processes the temporary file, copying it to the file argument(s) and standard output.

Examples

[edit]

This example searches the filewikipedia.txt for any lines containing the string "4DOS", makes a copy of the matching lines in4DOS.txt, sorts the lines, and writes them to the output file4DOSsorted.txt:

>find"4DOS" wikipedia.txt| tee 4DOS.txt| sort> 4DOSsorted.txt

PowerShell

[edit]

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] <String> [-InputObject <PSObject>]tee -Variable <String> [-InputObject <PSObject>]
  • -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 acceptswildcard characters that resolve to a single file.
  • -Variable <String> A reference to the input objects will be assigned to the specified variable.

The command is implemented as aReadOnlycommand alias that invokes the cmdlet namedMicrosoft.PowerShell.Utility\Tee-Object.

Examples

[edit]

The following displays the standard output of commandipconfig in theconsole window, and simultaneously saves a copy of it in the fileOutputFile.txt.

ipconfig|teeOutputFile.txt

The following shows that the piped input fortee can be filtered and thattee 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 fileABC.txt. To display and save all runningprocesses, filtered so that only programs starting with svc and owning more than 1000handles are output:

Get-Process|Where-Object{$_.Name-like"svc*"}|Tee-ObjectABC.txt|Where-Object{$_.Handles-gt1000}

See also

[edit]

References

[edit]
  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. Retrieved1 December 2013.
  2. ^"In Unix, what do some obscurely named commands stand for?". Archived fromthe original on 27 November 2005. Retrieved3 February 2012.
  3. ^Paul S. Dayan (1992).The OS-9 Guru - 1 : The Facts. Galactic Industrial Limited.ISBN 0-9519228-0-7.
  4. ^"Native Win32 ports of some GNU utilities".unxutils.sourceforge.net.Archived from the original on 9 February 2006. Retrieved11 August 2025.
  5. ^"reactos/reactos".GitHub. 3 January 2022.Archived from the original on 11 December 2017. Retrieved29 July 2019.
  6. ^IBM."IBM System i Version 7.2 Programming Qshell"(PDF).IBM.Archived(PDF) from the original on 18 September 2020. Retrieved5 September 2020.
  7. ^"tee: read from standard input and write to standard output and files".www.mankier.com.
  8. ^"ibiblio.org FreeDOS Package -- tee (Unix-like)".www.ibiblio.org.Archived from the original on 7 July 2018. Retrieved13 November 2018.
  9. ^"sponge(1): soak up stdin/write to file - Linux man page".linux.die.net.
  10. ^GNU Coreutils, tee invocation
  11. ^"GNU Coreutils: tee invocation".Archived from the original on 20 January 2016. Retrieved3 February 2016.

Further reading

[edit]

External links

[edit]
The WikibookGuide to Unix has a page on the topic of:Commands
File system
Processes
User environment
Text processing
Shell builtins
Searching
Documentation
Software development
Miscellaneous
File system
Processes
User environment
Text processing
Shell builtins
Networking
Searching
Software development
Miscellaneous
File system
Text utilities
Shell utilities
Ecosystem
Interpreters
Terminals
File system navigation
File management
Archiving
Disk management
Processes
Registry
User environment
File contents
Scripting
Networking
Maintenance and care
Boot management
Software development
Miscellaneous

Retrieved from "https://en.wikipedia.org/w/index.php?title=Tee_(command)&oldid=1336329942"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp