ArticleslgStudy

science

Tee (command)

Tee (command) is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Tee (command) rather than just read about it. In short: tee is a shell command that copies data from standard input to one or more files in addition to standard output, duplicating the input to each output. The name derives from the tee pipe fitting even though the tee command duplicates the input into each output instead of dividing the input into portions for each output.

Key takeaways

  • Tee (command) belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Tee (command) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Tee (command) from memory before moving on to harder problems.

Reference excerpt

tee is a shell command that copies data from standard input to one or more files in addition to standard output, duplicating the input to each output. The name derives from the tee pipe fitting even though the tee command duplicates the input into each output instead of dividing the input into portions for each output. The command is often used with pipes and filters. Similar behaving commands are provided by many shells although syntax varies. The command is provided in Unix and Unix-like systems, OS-9, MS-DOS / PC DOS and compatibles, Windows (e.g. 4NT, PowerShell, UnxUtils), ReactOS and IBM i. The Linux version was written by Mike Parker, Richard Stallman, and David MacKenzie. The FreeDOS version was developed by Jim Hall and is licensed under the GPL. Additionally the sponge command offers similar capabilities.

Unix 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. If a write to any file is not successful, writes to other files and standard output continue, but the exit status will indicate failure with a value greater than 0.

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

lint program.c | tee program.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.

lint program.c | tee -a program.lint

The following bypasses a limitation of the sudo 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.

In Bash, the output can be filtered before being written to the file—without affecting the output displayed—by using process substitution. The following removes common ANSI escape codes before writing to ls.txt, but retains them for display.

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

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

Examples 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:

PowerShell 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:

-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. The command is implemented as a ReadOnly command alias that invokes the cmdlet named Microsoft.PowerShell.Utility\Tee-Object.

Examples The following displays the standard output of command ipconfig in the console window, and simultaneously saves a copy of it in the file OutputFile.txt.

The following 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. To display and save all running processes, filtered so that only programs starting with svc and owning more than 1000 handles are output:

See also GNU Core Utilities – Collection of standard, Unix-based utilities from GNU List of POSIX commands syslog – Network event logging system and protocol

References

Further reading McElhearn, Kirk (2006). The Mac OS X Command Line: Unix Under the Hood. John Wiley & Sons. ISBN 978-0470113851.

External links

An introduction on Linux I/O Redirection "Linux I/O Redirection" Archived 10 June 2012 at the Wayback Machine with tee GNU tee manual tee: duplicate standard input – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group tee(1) – Plan 9 Programmer's Manual, Volume 1 tee(1) – Inferno General commands Manual Delphi-Tee - Delphi (software) OpenSource implementation

Worked examples

Example 1 — a first encounter with Tee (command)

Start with the simplest possible case. Write down what Tee (command) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Tee (command) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Tee (command) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Tee (command)

In research
Tee (command) appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Tee (command) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Tee (command) is common in secondary-school and first-year university syllabi. It links to neighbouring topics IBM i Qshell commands, Inferno (operating system) commands, Inter-process communication, so understanding it makes those chapters shorter.
In everyday life
Look for Tee (command) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Tee (command)” →

How to study Tee (command) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Tee (command) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Tee (command) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Tee (command) in simple terms?

tee is a shell command that copies data from standard input to one or more files in addition to standard output, duplicating the input to each output. The name derives from the tee pipe fitting even though the tee command duplicates the input into each output instead of dividing the input into port…

Why does Tee (command) matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Tee (command)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Tee (command).

Tags

  • IBM i Qshell commands
  • Inferno (operating system) commands
  • Inter-process communication
  • Plan 9 commands
  • ReactOS commands
  • Unix SUS2008 utilities
  • Unix text processing utilities
  • Windows administration
  • Windows commands

Keep exploring