What is the purpose of tee?
Clash Royale CLAN TAG#URR8PPP
up vote
58
down vote
favorite
All the usages of tee
I ever saw were such:
do_something | tee -a logfile
Or:
do_something_else | tee logfile
Is tee
invented for those that don't know you can do the same with shell pipe redirections? Such as:
do_something >> logfile
Or:
do_something_else > logfile
It's practically the same and it takes less keyboard hits to type out. What hidden features am I not seeing in tee
?
shell tee
New contributor
R Moog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
58
down vote
favorite
All the usages of tee
I ever saw were such:
do_something | tee -a logfile
Or:
do_something_else | tee logfile
Is tee
invented for those that don't know you can do the same with shell pipe redirections? Such as:
do_something >> logfile
Or:
do_something_else > logfile
It's practically the same and it takes less keyboard hits to type out. What hidden features am I not seeing in tee
?
shell tee
New contributor
R Moog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
17
How was this not answered by the very first line of the man page "...and write to standard output and files"? The answers are interesting, but broadly talking about how pipes are useful just reinforces how this Q seems too broad, and should perhaps have been closed.
– Xen2050
23 hours ago
add a comment |Â
up vote
58
down vote
favorite
up vote
58
down vote
favorite
All the usages of tee
I ever saw were such:
do_something | tee -a logfile
Or:
do_something_else | tee logfile
Is tee
invented for those that don't know you can do the same with shell pipe redirections? Such as:
do_something >> logfile
Or:
do_something_else > logfile
It's practically the same and it takes less keyboard hits to type out. What hidden features am I not seeing in tee
?
shell tee
New contributor
R Moog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
All the usages of tee
I ever saw were such:
do_something | tee -a logfile
Or:
do_something_else | tee logfile
Is tee
invented for those that don't know you can do the same with shell pipe redirections? Such as:
do_something >> logfile
Or:
do_something_else > logfile
It's practically the same and it takes less keyboard hits to type out. What hidden features am I not seeing in tee
?
shell tee
shell tee
New contributor
R Moog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
R Moog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 2 days ago
Attie
9,04732136
9,04732136
New contributor
R Moog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 days ago


R Moog
480124
480124
New contributor
R Moog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
R Moog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
R Moog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
17
How was this not answered by the very first line of the man page "...and write to standard output and files"? The answers are interesting, but broadly talking about how pipes are useful just reinforces how this Q seems too broad, and should perhaps have been closed.
– Xen2050
23 hours ago
add a comment |Â
17
How was this not answered by the very first line of the man page "...and write to standard output and files"? The answers are interesting, but broadly talking about how pipes are useful just reinforces how this Q seems too broad, and should perhaps have been closed.
– Xen2050
23 hours ago
17
17
How was this not answered by the very first line of the man page "...and write to standard output and files"? The answers are interesting, but broadly talking about how pipes are useful just reinforces how this Q seems too broad, and should perhaps have been closed.
– Xen2050
23 hours ago
How was this not answered by the very first line of the man page "...and write to standard output and files"? The answers are interesting, but broadly talking about how pipes are useful just reinforces how this Q seems too broad, and should perhaps have been closed.
– Xen2050
23 hours ago
add a comment |Â
10 Answers
10
active
oldest
votes
up vote
158
down vote
What you don't see is that do_something | tee -a logfile
puts the output into logfile
and to stdout, while do_something >> logfile
puts it only into the logfile.
The purpose of tee
is to produce a one input, multiple output scenario - just like in a 'T' crossing.
20
Multiple output is the key.tee
can even take multiple arguments and write to many files at once.
– Kamil Maciorowski
2 days ago
10
I would call it a tee pipe fitting, not a crossing (as in a road intersection?) Stuff comes in one way and goes out both ways.
– user20574
yesterday
Even after you said "'T' crossing" it didn't immediately occur to me that the command literally spells it out
– Sirap
yesterday
Oh it was meant to be like a T crossing? I used to assume it was a reference to golf tee.
– Anon
13 hours ago
add a comment |Â
up vote
92
down vote
Tee
is not useless
Maybe you knew that anyway? If not, read on! Or if you know how it works, but aren't sure why it exists, skip to the end to see how it fit in the with the Unix philosophy.
What is the purpose of tee
?
At its simplest, it takes data on standard input and writes that to standard output and one (or more) files. It has been likened to a plumbing tee piece in the way it splits one input into two outputs (and two directions).
Examples
Let's take your first example:
do_something | tee -a logfile
This takes the output of do_something
and appends it to logfile, while also displaying it to the user. In fact, the Wikipedia page on tee
has this as the second example:
To view and append 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 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.
The very next example has another use: escalation of permissions:
To allow escalation of permissions:
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 standard out 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.
Or perhaps you want to take the output of one command, write that somewhere and also use that as input to another command?
You can also use tee command to store the output of a command to a file and redirect the same output as an input to another command.
The following command will take a backup of the crontab entries, and pass the crontab entries as an input to sed command which will do the substitution. After the substitution, it will be added as a new cron job.
$ crontab -l | tee crontab-backup.txt | sed 's/old/new/' | crontab –
(credit to Tee command usage examples)
Tee
works with the Unix philosophy:
Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.
(Credit to Basics of the Unix Philosophy)
tee
fits all of these:
- it does one thing: creates an extra copy of input
- it works with other programs because it is the glue (or a 'T' plumbing piece if you prefer) that lets other programs work together as in the examples above
- it does this by manipulating a text stream given on standard input
@Joe:sudo tee -a
is probably a more recent innovation (I first saw it in Ubuntu guides / wikis especially for setting stuff in/proc/sys
, because switching to Ubuntu was when I switched to asudo
based system (how Ubuntu is configured by default) instead of usingsu
with a root password). I thinktee
predatessudo
, so it's not a reason fortee
existing. You don't needtee
for that, it's simply shorter to type interactively thansudo sh -c 'cat > output'
.
– Peter Cordes
yesterday
With modern shells like bash, you cantee
to feed two pipelines, likefoo | tee >(pipe2) | pipe1
. Or another fun one isffmpeg ... |& tee /dev/tty | sed 's/.*r// > encode.log
to see status-line updates interactively on the tty, while removing "lines" that end with carriage-return instead of newline for actual logging. (i.e. filter out the status-line updates). In general, you can stick atee /dev/tty
anywhere in a pipeline as a debug-print.
– Peter Cordes
yesterday
It's less a limitation of sudo you're working around and more a limitation of the shell's interpretation of >. When you run a command with sudo its stdout gets sent back to your shell program and further redirects with > are run with the shell's permissions. If you want to write with elevated permissions you need to have the elevated part of the pipeline be what does the writing. There are a large number of ways to do this depending on precisely what effect you're going for. If you really want to use > something like 'sudo bash -c "command > outfile" ' will do the job.
– Perkins
6 hours ago
add a comment |Â
up vote
50
down vote
It's practically the same and it takes less keyboard hits to type out.
It is not the same at all...
The following appear to be somewhat equivalent, but they're not:
$ echo "hi" > test.txt
$ echo "hi" | tee test.txt
hi
The critical difference is that the former has written the data only to the named file, while the latter has written hi
to the terminal (stdout
) and the named file, as shown below:
tee
allows you to write the data to a file and use it in an onward pipeline, allowing you to do useful things - like keeping data from partway through a pipeline:
grep '^look ' interesting_file.txt
| tee interesting_lines.txt
| sort
Or, you can write to a file with elevated privileges, without giving the whole pipeline elevated privileges (here echo
is run as the user, while tee
writes to the file as root
):
echo 0
| sudo tee /proc/sys/net/ipv4/ip_forward
With tee
, you can write to many files (and stdout
):
echo "hi"
| tee a.txt b.txt
It's also possible to use exec
with tee
to record all of a script's output to a file, while still allowing an observer (stdout
) to see the data:
exec > >( tee output.log )
2
Not to forgetexec > >(tee "$LOGFILE") 2>&1
in a bash script which lets the script output stdout and stderr to both, stdout and the file pointed to by$LOGFILE
.
– rexkogitans
2 days ago
@rexkogitans 2>&1 isn't that cmd batch syntax?
– dmb
2 days ago
@dmb: It's shell syntax for "send stderr(=2) to the same place as stdout(=1)"
– psmears
2 days ago
@rexkogitans It was a fair question really, I can't really know that you haven't used "Windoze" for a decade. I use2>&1
to drop output and err to txt files in windows.
– dmb
2 days ago
1
@dmb I am sorry for sounding rude. It's all about psmears' comment. Obviously, Windows adopted Unix-style here.
– rexkogitans
2 days ago
add a comment |Â
up vote
16
down vote
No. You happen to mention one of the few examples where you could indeed redirect to the file using >
and >>
operators.
But Tee can do much more. Because you pipe to it, you can then pipe to something else.
A good example is listed on the wikipedia page:
find "4DOS" wikipedia.txt | tee 4DOS.txt | sort > 4DOSsorted.txt
Basically, you can pipe to Tee, so you can then pipe from Tee to something else. If all you want to do is write a log file, yes, then you don't really need Tee.
add a comment |Â
up vote
11
down vote
Nitpick on @bertieb's answer that says 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.
There is no inherent limitation, only a misunderstanding of how the command is processed.
Example:
sudo echo 0 > /proc/sys/net/ipv4/ip_forward
The current shell parses the command line. It finds the output redirection and performs that. Then it executes the command, which is the sudo
and provides the remaining command line as arguments to the executed command. If the current shell does not have root permissions, then the output redirection will fail.
echo 0 | sudo tee /proc/sys/net/ipv4/ip_forward
This works because the output redirection is deferred to the tee
command, which at that point does have root permissions because it was executed via sudo
.
sudo bash -c "echo 0 > /proc/sys/net/ipv4/ip_forward"
This works because the shell doing the redirection has root permissions.
1
Also, you might needsudo
for the command, but not for the file being output and the redirection works just fine:sudo foo-needs-privilege > /tmp/this-output-file-doesnt
– Dennis Williamson
2 days ago
add a comment |Â
up vote
11
down vote
tee
is far from useless. I use it all the time and am glad it exists. It's a very useful tool if you have a pipeline that you want to split up. A very simple example is that you have some directory $d
that you want to tar and you also want to hash it because you're paranoid (like I am) and don't trust the storage medium to hold the data reliably. You could write it to the disk first and then hash it, but that'd fail if the archive gets corrupted before it's hashed. Furthermore, you'd have to read it and if you work on files that are several hundred GB in size a lot, you will know that you really don't want to read them again if it doesn't have to be.
So what I do is simply this:
tar -c "$d" | tee >(sha256sum) >(cat > "$d"".tar") > /dev/null
It creates the tar ball and pipes it to tee which then pipes it to two sub-shells, in one of which it's hashed and in the other of which it's written to the disk.
It's also great if you want to perform several operations on a big file:
< file.tar.gz tee >(sha256sum) >(tar -xz) /other/storage/location/file.tar.gz
Reads the file once, hashes it (so you can check whether it's still as it should be), extracts it, and copies it to a different location. No need to read it three times for that.
1
Nitpick:tee
does not create the subshells; the calling shell runssha5sum
andcat
and connects their output to file descriptors which are passed totee
. Also, a useless use ofcat
; you can use input redirection to havetee
read directly fromfile.tar.gz
.
– chepner
2 days ago
@chepner You're right about the first interjection but you're completely wrong about the second one. I like writing my pipelines in order, so denoting the input at the right is terrible for readability and doing so is clearly objectively inferior to my method and totally not a subjective preference of mine.cat
is love.cat
is life.
– UTF-8
2 days ago
5
You can also write< file.tar.gz tee >(sha256sum) ...
if you are concerned about the lexical ordering of the redirections. That doesn't change the fact that there is no need for an entirely separate process just to feed a single file totee
.
– chepner
2 days ago
1
@chepner Cool, thank you! Learned something today. :)
– UTF-8
2 days ago
Useless use ofdd
as well. Use/other/storage/location/file.tar.gz
as an arg totee
, so it writes to the file directly instead of to a pipe to another process. Same problem with the first example: you're gaining no readability at all by piping the output throughcat > "$d".tar
. Wait, you actually have the quotes on the".tar"
but the expansion of$d
is unquoted?!?)
– Peter Cordes
yesterday
 |Â
show 5 more comments
up vote
7
down vote
This is a tee:
A T-shaped pipe fitting. It has an inlet, and two separate outlets.
In other words, it splits one pipe into two; like a fork in the road.
Similarly, tee
is a pipe (|
) that allows you to redirect your standard input to two separate output locations.
Example
Say for instance, you type ls /
.
You'll get an output that looks something like:
Applications Network Users bin dev net private tmp var
Library System Volumes cores etc home opt sbin usr
Redirect the output to a text file, ls / > ls.txt
, and no output is displayed in the shell, only in the resulting text file.
Want to see the output, AND pass it to a text file at the same time?
Add a tee
to your pipe (|
) ie: ls / | tee ls.txt
Compare the two:
ls / > ls.txt
ls / | tee ls.txt
add a comment |Â
up vote
6
down vote
The most common use of tee is to see the text on the terminal at the same time you send it to the file (or files). The wording of your question assumes you only ever write text to logfiles. I have scripts which write lists of filenames or directory names to trigger files (to be processed by other scripts asynchronously) and I use tee to send the same content to stdout. All stdout is directed to the logs. So I have my text where I want it and I have a log entry recording that I did this, all from a single 'echo' statement
tee is also the best method in Unix for making multiple identical files. I use it occasionally for making multiple empty files, like this ...
:|tee file01 file02 file03
New contributor
Wil Young is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5
why nottouch
? (more immediately obvious what is happening)
– Attie
2 days ago
add a comment |Â
up vote
6
down vote
As other people have mentioned, piping output to the tee
command writes that output to both a file and to stdout.
I often use tee
when I want to capture output from a command that takes a long time to run, while also wanting to visually inspect the output as the command makes it available. That way, I don't have to wait for the command to finish running before I inspect the output.
What doesn't seem to have been mentioned yet (unless I missed it), is that the tee
command can also write to multiple files at once. For example:
ls *.png | tee a.txt b.txt
will write out all the *.png
files in the current directory to two different files (a.txt
and b.txt
) at once.
In fact, you can type text to several different files at once with tee
like this:
$ tee --append a.txt b.txt c.txt d.txt
These lines are appended to four different files,
and are also written to stdout.
CTRL-D
New contributor
J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
0
down vote
Imagine, you want to write the output of a command to a log file AND print to stdout. When you need to do it at the same time, then you need tee
.
A use case is to have build scripts that write the whole build to stdout (e.g. for Jenkins) but important stuff at the same time to a separate log file (for summary emails).
You'll really start missing tee
when you have to script in Windows. There is no tee
and that is really annoying.
Isn't it trivial to create?
– Lightness Races in Orbit
yesterday
It is not possible with batch/cmd as you can not split a stream of output from a command easily.
– domih
15 hours ago
Right but like a three-line C++ program...
– Lightness Races in Orbit
15 hours ago
The Windows unxutils distribution has many Unix command line tools which, unlike some distributions, do not pollute your Windows execution environment. The biggest limitation is on "glob"bing, which works differently on Unix/Linux than on Windows. "tee" is among the tools available.
– cmm
11 hours ago
add a comment |Â
10 Answers
10
active
oldest
votes
10 Answers
10
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
158
down vote
What you don't see is that do_something | tee -a logfile
puts the output into logfile
and to stdout, while do_something >> logfile
puts it only into the logfile.
The purpose of tee
is to produce a one input, multiple output scenario - just like in a 'T' crossing.
20
Multiple output is the key.tee
can even take multiple arguments and write to many files at once.
– Kamil Maciorowski
2 days ago
10
I would call it a tee pipe fitting, not a crossing (as in a road intersection?) Stuff comes in one way and goes out both ways.
– user20574
yesterday
Even after you said "'T' crossing" it didn't immediately occur to me that the command literally spells it out
– Sirap
yesterday
Oh it was meant to be like a T crossing? I used to assume it was a reference to golf tee.
– Anon
13 hours ago
add a comment |Â
up vote
158
down vote
What you don't see is that do_something | tee -a logfile
puts the output into logfile
and to stdout, while do_something >> logfile
puts it only into the logfile.
The purpose of tee
is to produce a one input, multiple output scenario - just like in a 'T' crossing.
20
Multiple output is the key.tee
can even take multiple arguments and write to many files at once.
– Kamil Maciorowski
2 days ago
10
I would call it a tee pipe fitting, not a crossing (as in a road intersection?) Stuff comes in one way and goes out both ways.
– user20574
yesterday
Even after you said "'T' crossing" it didn't immediately occur to me that the command literally spells it out
– Sirap
yesterday
Oh it was meant to be like a T crossing? I used to assume it was a reference to golf tee.
– Anon
13 hours ago
add a comment |Â
up vote
158
down vote
up vote
158
down vote
What you don't see is that do_something | tee -a logfile
puts the output into logfile
and to stdout, while do_something >> logfile
puts it only into the logfile.
The purpose of tee
is to produce a one input, multiple output scenario - just like in a 'T' crossing.
What you don't see is that do_something | tee -a logfile
puts the output into logfile
and to stdout, while do_something >> logfile
puts it only into the logfile.
The purpose of tee
is to produce a one input, multiple output scenario - just like in a 'T' crossing.
edited yesterday
iono
23527
23527
answered 2 days ago
Eugen Rieck
7,57921922
7,57921922
20
Multiple output is the key.tee
can even take multiple arguments and write to many files at once.
– Kamil Maciorowski
2 days ago
10
I would call it a tee pipe fitting, not a crossing (as in a road intersection?) Stuff comes in one way and goes out both ways.
– user20574
yesterday
Even after you said "'T' crossing" it didn't immediately occur to me that the command literally spells it out
– Sirap
yesterday
Oh it was meant to be like a T crossing? I used to assume it was a reference to golf tee.
– Anon
13 hours ago
add a comment |Â
20
Multiple output is the key.tee
can even take multiple arguments and write to many files at once.
– Kamil Maciorowski
2 days ago
10
I would call it a tee pipe fitting, not a crossing (as in a road intersection?) Stuff comes in one way and goes out both ways.
– user20574
yesterday
Even after you said "'T' crossing" it didn't immediately occur to me that the command literally spells it out
– Sirap
yesterday
Oh it was meant to be like a T crossing? I used to assume it was a reference to golf tee.
– Anon
13 hours ago
20
20
Multiple output is the key.
tee
can even take multiple arguments and write to many files at once.– Kamil Maciorowski
2 days ago
Multiple output is the key.
tee
can even take multiple arguments and write to many files at once.– Kamil Maciorowski
2 days ago
10
10
I would call it a tee pipe fitting, not a crossing (as in a road intersection?) Stuff comes in one way and goes out both ways.
– user20574
yesterday
I would call it a tee pipe fitting, not a crossing (as in a road intersection?) Stuff comes in one way and goes out both ways.
– user20574
yesterday
Even after you said "'T' crossing" it didn't immediately occur to me that the command literally spells it out
– Sirap
yesterday
Even after you said "'T' crossing" it didn't immediately occur to me that the command literally spells it out
– Sirap
yesterday
Oh it was meant to be like a T crossing? I used to assume it was a reference to golf tee.
– Anon
13 hours ago
Oh it was meant to be like a T crossing? I used to assume it was a reference to golf tee.
– Anon
13 hours ago
add a comment |Â
up vote
92
down vote
Tee
is not useless
Maybe you knew that anyway? If not, read on! Or if you know how it works, but aren't sure why it exists, skip to the end to see how it fit in the with the Unix philosophy.
What is the purpose of tee
?
At its simplest, it takes data on standard input and writes that to standard output and one (or more) files. It has been likened to a plumbing tee piece in the way it splits one input into two outputs (and two directions).
Examples
Let's take your first example:
do_something | tee -a logfile
This takes the output of do_something
and appends it to logfile, while also displaying it to the user. In fact, the Wikipedia page on tee
has this as the second example:
To view and append 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 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.
The very next example has another use: escalation of permissions:
To allow escalation of permissions:
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 standard out 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.
Or perhaps you want to take the output of one command, write that somewhere and also use that as input to another command?
You can also use tee command to store the output of a command to a file and redirect the same output as an input to another command.
The following command will take a backup of the crontab entries, and pass the crontab entries as an input to sed command which will do the substitution. After the substitution, it will be added as a new cron job.
$ crontab -l | tee crontab-backup.txt | sed 's/old/new/' | crontab –
(credit to Tee command usage examples)
Tee
works with the Unix philosophy:
Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.
(Credit to Basics of the Unix Philosophy)
tee
fits all of these:
- it does one thing: creates an extra copy of input
- it works with other programs because it is the glue (or a 'T' plumbing piece if you prefer) that lets other programs work together as in the examples above
- it does this by manipulating a text stream given on standard input
@Joe:sudo tee -a
is probably a more recent innovation (I first saw it in Ubuntu guides / wikis especially for setting stuff in/proc/sys
, because switching to Ubuntu was when I switched to asudo
based system (how Ubuntu is configured by default) instead of usingsu
with a root password). I thinktee
predatessudo
, so it's not a reason fortee
existing. You don't needtee
for that, it's simply shorter to type interactively thansudo sh -c 'cat > output'
.
– Peter Cordes
yesterday
With modern shells like bash, you cantee
to feed two pipelines, likefoo | tee >(pipe2) | pipe1
. Or another fun one isffmpeg ... |& tee /dev/tty | sed 's/.*r// > encode.log
to see status-line updates interactively on the tty, while removing "lines" that end with carriage-return instead of newline for actual logging. (i.e. filter out the status-line updates). In general, you can stick atee /dev/tty
anywhere in a pipeline as a debug-print.
– Peter Cordes
yesterday
It's less a limitation of sudo you're working around and more a limitation of the shell's interpretation of >. When you run a command with sudo its stdout gets sent back to your shell program and further redirects with > are run with the shell's permissions. If you want to write with elevated permissions you need to have the elevated part of the pipeline be what does the writing. There are a large number of ways to do this depending on precisely what effect you're going for. If you really want to use > something like 'sudo bash -c "command > outfile" ' will do the job.
– Perkins
6 hours ago
add a comment |Â
up vote
92
down vote
Tee
is not useless
Maybe you knew that anyway? If not, read on! Or if you know how it works, but aren't sure why it exists, skip to the end to see how it fit in the with the Unix philosophy.
What is the purpose of tee
?
At its simplest, it takes data on standard input and writes that to standard output and one (or more) files. It has been likened to a plumbing tee piece in the way it splits one input into two outputs (and two directions).
Examples
Let's take your first example:
do_something | tee -a logfile
This takes the output of do_something
and appends it to logfile, while also displaying it to the user. In fact, the Wikipedia page on tee
has this as the second example:
To view and append 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 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.
The very next example has another use: escalation of permissions:
To allow escalation of permissions:
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 standard out 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.
Or perhaps you want to take the output of one command, write that somewhere and also use that as input to another command?
You can also use tee command to store the output of a command to a file and redirect the same output as an input to another command.
The following command will take a backup of the crontab entries, and pass the crontab entries as an input to sed command which will do the substitution. After the substitution, it will be added as a new cron job.
$ crontab -l | tee crontab-backup.txt | sed 's/old/new/' | crontab –
(credit to Tee command usage examples)
Tee
works with the Unix philosophy:
Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.
(Credit to Basics of the Unix Philosophy)
tee
fits all of these:
- it does one thing: creates an extra copy of input
- it works with other programs because it is the glue (or a 'T' plumbing piece if you prefer) that lets other programs work together as in the examples above
- it does this by manipulating a text stream given on standard input
@Joe:sudo tee -a
is probably a more recent innovation (I first saw it in Ubuntu guides / wikis especially for setting stuff in/proc/sys
, because switching to Ubuntu was when I switched to asudo
based system (how Ubuntu is configured by default) instead of usingsu
with a root password). I thinktee
predatessudo
, so it's not a reason fortee
existing. You don't needtee
for that, it's simply shorter to type interactively thansudo sh -c 'cat > output'
.
– Peter Cordes
yesterday
With modern shells like bash, you cantee
to feed two pipelines, likefoo | tee >(pipe2) | pipe1
. Or another fun one isffmpeg ... |& tee /dev/tty | sed 's/.*r// > encode.log
to see status-line updates interactively on the tty, while removing "lines" that end with carriage-return instead of newline for actual logging. (i.e. filter out the status-line updates). In general, you can stick atee /dev/tty
anywhere in a pipeline as a debug-print.
– Peter Cordes
yesterday
It's less a limitation of sudo you're working around and more a limitation of the shell's interpretation of >. When you run a command with sudo its stdout gets sent back to your shell program and further redirects with > are run with the shell's permissions. If you want to write with elevated permissions you need to have the elevated part of the pipeline be what does the writing. There are a large number of ways to do this depending on precisely what effect you're going for. If you really want to use > something like 'sudo bash -c "command > outfile" ' will do the job.
– Perkins
6 hours ago
add a comment |Â
up vote
92
down vote
up vote
92
down vote
Tee
is not useless
Maybe you knew that anyway? If not, read on! Or if you know how it works, but aren't sure why it exists, skip to the end to see how it fit in the with the Unix philosophy.
What is the purpose of tee
?
At its simplest, it takes data on standard input and writes that to standard output and one (or more) files. It has been likened to a plumbing tee piece in the way it splits one input into two outputs (and two directions).
Examples
Let's take your first example:
do_something | tee -a logfile
This takes the output of do_something
and appends it to logfile, while also displaying it to the user. In fact, the Wikipedia page on tee
has this as the second example:
To view and append 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 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.
The very next example has another use: escalation of permissions:
To allow escalation of permissions:
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 standard out 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.
Or perhaps you want to take the output of one command, write that somewhere and also use that as input to another command?
You can also use tee command to store the output of a command to a file and redirect the same output as an input to another command.
The following command will take a backup of the crontab entries, and pass the crontab entries as an input to sed command which will do the substitution. After the substitution, it will be added as a new cron job.
$ crontab -l | tee crontab-backup.txt | sed 's/old/new/' | crontab –
(credit to Tee command usage examples)
Tee
works with the Unix philosophy:
Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.
(Credit to Basics of the Unix Philosophy)
tee
fits all of these:
- it does one thing: creates an extra copy of input
- it works with other programs because it is the glue (or a 'T' plumbing piece if you prefer) that lets other programs work together as in the examples above
- it does this by manipulating a text stream given on standard input
Tee
is not useless
Maybe you knew that anyway? If not, read on! Or if you know how it works, but aren't sure why it exists, skip to the end to see how it fit in the with the Unix philosophy.
What is the purpose of tee
?
At its simplest, it takes data on standard input and writes that to standard output and one (or more) files. It has been likened to a plumbing tee piece in the way it splits one input into two outputs (and two directions).
Examples
Let's take your first example:
do_something | tee -a logfile
This takes the output of do_something
and appends it to logfile, while also displaying it to the user. In fact, the Wikipedia page on tee
has this as the second example:
To view and append 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 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.
The very next example has another use: escalation of permissions:
To allow escalation of permissions:
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 standard out 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.
Or perhaps you want to take the output of one command, write that somewhere and also use that as input to another command?
You can also use tee command to store the output of a command to a file and redirect the same output as an input to another command.
The following command will take a backup of the crontab entries, and pass the crontab entries as an input to sed command which will do the substitution. After the substitution, it will be added as a new cron job.
$ crontab -l | tee crontab-backup.txt | sed 's/old/new/' | crontab –
(credit to Tee command usage examples)
Tee
works with the Unix philosophy:
Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.
(Credit to Basics of the Unix Philosophy)
tee
fits all of these:
- it does one thing: creates an extra copy of input
- it works with other programs because it is the glue (or a 'T' plumbing piece if you prefer) that lets other programs work together as in the examples above
- it does this by manipulating a text stream given on standard input
edited yesterday


Peter Cordes
2,2751521
2,2751521
answered 2 days ago


bertieb
4,95492141
4,95492141
@Joe:sudo tee -a
is probably a more recent innovation (I first saw it in Ubuntu guides / wikis especially for setting stuff in/proc/sys
, because switching to Ubuntu was when I switched to asudo
based system (how Ubuntu is configured by default) instead of usingsu
with a root password). I thinktee
predatessudo
, so it's not a reason fortee
existing. You don't needtee
for that, it's simply shorter to type interactively thansudo sh -c 'cat > output'
.
– Peter Cordes
yesterday
With modern shells like bash, you cantee
to feed two pipelines, likefoo | tee >(pipe2) | pipe1
. Or another fun one isffmpeg ... |& tee /dev/tty | sed 's/.*r// > encode.log
to see status-line updates interactively on the tty, while removing "lines" that end with carriage-return instead of newline for actual logging. (i.e. filter out the status-line updates). In general, you can stick atee /dev/tty
anywhere in a pipeline as a debug-print.
– Peter Cordes
yesterday
It's less a limitation of sudo you're working around and more a limitation of the shell's interpretation of >. When you run a command with sudo its stdout gets sent back to your shell program and further redirects with > are run with the shell's permissions. If you want to write with elevated permissions you need to have the elevated part of the pipeline be what does the writing. There are a large number of ways to do this depending on precisely what effect you're going for. If you really want to use > something like 'sudo bash -c "command > outfile" ' will do the job.
– Perkins
6 hours ago
add a comment |Â
@Joe:sudo tee -a
is probably a more recent innovation (I first saw it in Ubuntu guides / wikis especially for setting stuff in/proc/sys
, because switching to Ubuntu was when I switched to asudo
based system (how Ubuntu is configured by default) instead of usingsu
with a root password). I thinktee
predatessudo
, so it's not a reason fortee
existing. You don't needtee
for that, it's simply shorter to type interactively thansudo sh -c 'cat > output'
.
– Peter Cordes
yesterday
With modern shells like bash, you cantee
to feed two pipelines, likefoo | tee >(pipe2) | pipe1
. Or another fun one isffmpeg ... |& tee /dev/tty | sed 's/.*r// > encode.log
to see status-line updates interactively on the tty, while removing "lines" that end with carriage-return instead of newline for actual logging. (i.e. filter out the status-line updates). In general, you can stick atee /dev/tty
anywhere in a pipeline as a debug-print.
– Peter Cordes
yesterday
It's less a limitation of sudo you're working around and more a limitation of the shell's interpretation of >. When you run a command with sudo its stdout gets sent back to your shell program and further redirects with > are run with the shell's permissions. If you want to write with elevated permissions you need to have the elevated part of the pipeline be what does the writing. There are a large number of ways to do this depending on precisely what effect you're going for. If you really want to use > something like 'sudo bash -c "command > outfile" ' will do the job.
– Perkins
6 hours ago
@Joe:
sudo tee -a
is probably a more recent innovation (I first saw it in Ubuntu guides / wikis especially for setting stuff in /proc/sys
, because switching to Ubuntu was when I switched to a sudo
based system (how Ubuntu is configured by default) instead of using su
with a root password). I think tee
predates sudo
, so it's not a reason for tee
existing. You don't need tee
for that, it's simply shorter to type interactively than sudo sh -c 'cat > output'
.– Peter Cordes
yesterday
@Joe:
sudo tee -a
is probably a more recent innovation (I first saw it in Ubuntu guides / wikis especially for setting stuff in /proc/sys
, because switching to Ubuntu was when I switched to a sudo
based system (how Ubuntu is configured by default) instead of using su
with a root password). I think tee
predates sudo
, so it's not a reason for tee
existing. You don't need tee
for that, it's simply shorter to type interactively than sudo sh -c 'cat > output'
.– Peter Cordes
yesterday
With modern shells like bash, you can
tee
to feed two pipelines, like foo | tee >(pipe2) | pipe1
. Or another fun one is ffmpeg ... |& tee /dev/tty | sed 's/.*r// > encode.log
to see status-line updates interactively on the tty, while removing "lines" that end with carriage-return instead of newline for actual logging. (i.e. filter out the status-line updates). In general, you can stick a tee /dev/tty
anywhere in a pipeline as a debug-print.– Peter Cordes
yesterday
With modern shells like bash, you can
tee
to feed two pipelines, like foo | tee >(pipe2) | pipe1
. Or another fun one is ffmpeg ... |& tee /dev/tty | sed 's/.*r// > encode.log
to see status-line updates interactively on the tty, while removing "lines" that end with carriage-return instead of newline for actual logging. (i.e. filter out the status-line updates). In general, you can stick a tee /dev/tty
anywhere in a pipeline as a debug-print.– Peter Cordes
yesterday
It's less a limitation of sudo you're working around and more a limitation of the shell's interpretation of >. When you run a command with sudo its stdout gets sent back to your shell program and further redirects with > are run with the shell's permissions. If you want to write with elevated permissions you need to have the elevated part of the pipeline be what does the writing. There are a large number of ways to do this depending on precisely what effect you're going for. If you really want to use > something like 'sudo bash -c "command > outfile" ' will do the job.
– Perkins
6 hours ago
It's less a limitation of sudo you're working around and more a limitation of the shell's interpretation of >. When you run a command with sudo its stdout gets sent back to your shell program and further redirects with > are run with the shell's permissions. If you want to write with elevated permissions you need to have the elevated part of the pipeline be what does the writing. There are a large number of ways to do this depending on precisely what effect you're going for. If you really want to use > something like 'sudo bash -c "command > outfile" ' will do the job.
– Perkins
6 hours ago
add a comment |Â
up vote
50
down vote
It's practically the same and it takes less keyboard hits to type out.
It is not the same at all...
The following appear to be somewhat equivalent, but they're not:
$ echo "hi" > test.txt
$ echo "hi" | tee test.txt
hi
The critical difference is that the former has written the data only to the named file, while the latter has written hi
to the terminal (stdout
) and the named file, as shown below:
tee
allows you to write the data to a file and use it in an onward pipeline, allowing you to do useful things - like keeping data from partway through a pipeline:
grep '^look ' interesting_file.txt
| tee interesting_lines.txt
| sort
Or, you can write to a file with elevated privileges, without giving the whole pipeline elevated privileges (here echo
is run as the user, while tee
writes to the file as root
):
echo 0
| sudo tee /proc/sys/net/ipv4/ip_forward
With tee
, you can write to many files (and stdout
):
echo "hi"
| tee a.txt b.txt
It's also possible to use exec
with tee
to record all of a script's output to a file, while still allowing an observer (stdout
) to see the data:
exec > >( tee output.log )
2
Not to forgetexec > >(tee "$LOGFILE") 2>&1
in a bash script which lets the script output stdout and stderr to both, stdout and the file pointed to by$LOGFILE
.
– rexkogitans
2 days ago
@rexkogitans 2>&1 isn't that cmd batch syntax?
– dmb
2 days ago
@dmb: It's shell syntax for "send stderr(=2) to the same place as stdout(=1)"
– psmears
2 days ago
@rexkogitans It was a fair question really, I can't really know that you haven't used "Windoze" for a decade. I use2>&1
to drop output and err to txt files in windows.
– dmb
2 days ago
1
@dmb I am sorry for sounding rude. It's all about psmears' comment. Obviously, Windows adopted Unix-style here.
– rexkogitans
2 days ago
add a comment |Â
up vote
50
down vote
It's practically the same and it takes less keyboard hits to type out.
It is not the same at all...
The following appear to be somewhat equivalent, but they're not:
$ echo "hi" > test.txt
$ echo "hi" | tee test.txt
hi
The critical difference is that the former has written the data only to the named file, while the latter has written hi
to the terminal (stdout
) and the named file, as shown below:
tee
allows you to write the data to a file and use it in an onward pipeline, allowing you to do useful things - like keeping data from partway through a pipeline:
grep '^look ' interesting_file.txt
| tee interesting_lines.txt
| sort
Or, you can write to a file with elevated privileges, without giving the whole pipeline elevated privileges (here echo
is run as the user, while tee
writes to the file as root
):
echo 0
| sudo tee /proc/sys/net/ipv4/ip_forward
With tee
, you can write to many files (and stdout
):
echo "hi"
| tee a.txt b.txt
It's also possible to use exec
with tee
to record all of a script's output to a file, while still allowing an observer (stdout
) to see the data:
exec > >( tee output.log )
2
Not to forgetexec > >(tee "$LOGFILE") 2>&1
in a bash script which lets the script output stdout and stderr to both, stdout and the file pointed to by$LOGFILE
.
– rexkogitans
2 days ago
@rexkogitans 2>&1 isn't that cmd batch syntax?
– dmb
2 days ago
@dmb: It's shell syntax for "send stderr(=2) to the same place as stdout(=1)"
– psmears
2 days ago
@rexkogitans It was a fair question really, I can't really know that you haven't used "Windoze" for a decade. I use2>&1
to drop output and err to txt files in windows.
– dmb
2 days ago
1
@dmb I am sorry for sounding rude. It's all about psmears' comment. Obviously, Windows adopted Unix-style here.
– rexkogitans
2 days ago
add a comment |Â
up vote
50
down vote
up vote
50
down vote
It's practically the same and it takes less keyboard hits to type out.
It is not the same at all...
The following appear to be somewhat equivalent, but they're not:
$ echo "hi" > test.txt
$ echo "hi" | tee test.txt
hi
The critical difference is that the former has written the data only to the named file, while the latter has written hi
to the terminal (stdout
) and the named file, as shown below:
tee
allows you to write the data to a file and use it in an onward pipeline, allowing you to do useful things - like keeping data from partway through a pipeline:
grep '^look ' interesting_file.txt
| tee interesting_lines.txt
| sort
Or, you can write to a file with elevated privileges, without giving the whole pipeline elevated privileges (here echo
is run as the user, while tee
writes to the file as root
):
echo 0
| sudo tee /proc/sys/net/ipv4/ip_forward
With tee
, you can write to many files (and stdout
):
echo "hi"
| tee a.txt b.txt
It's also possible to use exec
with tee
to record all of a script's output to a file, while still allowing an observer (stdout
) to see the data:
exec > >( tee output.log )
It's practically the same and it takes less keyboard hits to type out.
It is not the same at all...
The following appear to be somewhat equivalent, but they're not:
$ echo "hi" > test.txt
$ echo "hi" | tee test.txt
hi
The critical difference is that the former has written the data only to the named file, while the latter has written hi
to the terminal (stdout
) and the named file, as shown below:
tee
allows you to write the data to a file and use it in an onward pipeline, allowing you to do useful things - like keeping data from partway through a pipeline:
grep '^look ' interesting_file.txt
| tee interesting_lines.txt
| sort
Or, you can write to a file with elevated privileges, without giving the whole pipeline elevated privileges (here echo
is run as the user, while tee
writes to the file as root
):
echo 0
| sudo tee /proc/sys/net/ipv4/ip_forward
With tee
, you can write to many files (and stdout
):
echo "hi"
| tee a.txt b.txt
It's also possible to use exec
with tee
to record all of a script's output to a file, while still allowing an observer (stdout
) to see the data:
exec > >( tee output.log )
edited yesterday
answered 2 days ago
Attie
9,04732136
9,04732136
2
Not to forgetexec > >(tee "$LOGFILE") 2>&1
in a bash script which lets the script output stdout and stderr to both, stdout and the file pointed to by$LOGFILE
.
– rexkogitans
2 days ago
@rexkogitans 2>&1 isn't that cmd batch syntax?
– dmb
2 days ago
@dmb: It's shell syntax for "send stderr(=2) to the same place as stdout(=1)"
– psmears
2 days ago
@rexkogitans It was a fair question really, I can't really know that you haven't used "Windoze" for a decade. I use2>&1
to drop output and err to txt files in windows.
– dmb
2 days ago
1
@dmb I am sorry for sounding rude. It's all about psmears' comment. Obviously, Windows adopted Unix-style here.
– rexkogitans
2 days ago
add a comment |Â
2
Not to forgetexec > >(tee "$LOGFILE") 2>&1
in a bash script which lets the script output stdout and stderr to both, stdout and the file pointed to by$LOGFILE
.
– rexkogitans
2 days ago
@rexkogitans 2>&1 isn't that cmd batch syntax?
– dmb
2 days ago
@dmb: It's shell syntax for "send stderr(=2) to the same place as stdout(=1)"
– psmears
2 days ago
@rexkogitans It was a fair question really, I can't really know that you haven't used "Windoze" for a decade. I use2>&1
to drop output and err to txt files in windows.
– dmb
2 days ago
1
@dmb I am sorry for sounding rude. It's all about psmears' comment. Obviously, Windows adopted Unix-style here.
– rexkogitans
2 days ago
2
2
Not to forget
exec > >(tee "$LOGFILE") 2>&1
in a bash script which lets the script output stdout and stderr to both, stdout and the file pointed to by $LOGFILE
.– rexkogitans
2 days ago
Not to forget
exec > >(tee "$LOGFILE") 2>&1
in a bash script which lets the script output stdout and stderr to both, stdout and the file pointed to by $LOGFILE
.– rexkogitans
2 days ago
@rexkogitans 2>&1 isn't that cmd batch syntax?
– dmb
2 days ago
@rexkogitans 2>&1 isn't that cmd batch syntax?
– dmb
2 days ago
@dmb: It's shell syntax for "send stderr(=2) to the same place as stdout(=1)"
– psmears
2 days ago
@dmb: It's shell syntax for "send stderr(=2) to the same place as stdout(=1)"
– psmears
2 days ago
@rexkogitans It was a fair question really, I can't really know that you haven't used "Windoze" for a decade. I use
2>&1
to drop output and err to txt files in windows.– dmb
2 days ago
@rexkogitans It was a fair question really, I can't really know that you haven't used "Windoze" for a decade. I use
2>&1
to drop output and err to txt files in windows.– dmb
2 days ago
1
1
@dmb I am sorry for sounding rude. It's all about psmears' comment. Obviously, Windows adopted Unix-style here.
– rexkogitans
2 days ago
@dmb I am sorry for sounding rude. It's all about psmears' comment. Obviously, Windows adopted Unix-style here.
– rexkogitans
2 days ago
add a comment |Â
up vote
16
down vote
No. You happen to mention one of the few examples where you could indeed redirect to the file using >
and >>
operators.
But Tee can do much more. Because you pipe to it, you can then pipe to something else.
A good example is listed on the wikipedia page:
find "4DOS" wikipedia.txt | tee 4DOS.txt | sort > 4DOSsorted.txt
Basically, you can pipe to Tee, so you can then pipe from Tee to something else. If all you want to do is write a log file, yes, then you don't really need Tee.
add a comment |Â
up vote
16
down vote
No. You happen to mention one of the few examples where you could indeed redirect to the file using >
and >>
operators.
But Tee can do much more. Because you pipe to it, you can then pipe to something else.
A good example is listed on the wikipedia page:
find "4DOS" wikipedia.txt | tee 4DOS.txt | sort > 4DOSsorted.txt
Basically, you can pipe to Tee, so you can then pipe from Tee to something else. If all you want to do is write a log file, yes, then you don't really need Tee.
add a comment |Â
up vote
16
down vote
up vote
16
down vote
No. You happen to mention one of the few examples where you could indeed redirect to the file using >
and >>
operators.
But Tee can do much more. Because you pipe to it, you can then pipe to something else.
A good example is listed on the wikipedia page:
find "4DOS" wikipedia.txt | tee 4DOS.txt | sort > 4DOSsorted.txt
Basically, you can pipe to Tee, so you can then pipe from Tee to something else. If all you want to do is write a log file, yes, then you don't really need Tee.
No. You happen to mention one of the few examples where you could indeed redirect to the file using >
and >>
operators.
But Tee can do much more. Because you pipe to it, you can then pipe to something else.
A good example is listed on the wikipedia page:
find "4DOS" wikipedia.txt | tee 4DOS.txt | sort > 4DOSsorted.txt
Basically, you can pipe to Tee, so you can then pipe from Tee to something else. If all you want to do is write a log file, yes, then you don't really need Tee.
answered 2 days ago


LPChip
33.4k44479
33.4k44479
add a comment |Â
add a comment |Â
up vote
11
down vote
Nitpick on @bertieb's answer that says 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.
There is no inherent limitation, only a misunderstanding of how the command is processed.
Example:
sudo echo 0 > /proc/sys/net/ipv4/ip_forward
The current shell parses the command line. It finds the output redirection and performs that. Then it executes the command, which is the sudo
and provides the remaining command line as arguments to the executed command. If the current shell does not have root permissions, then the output redirection will fail.
echo 0 | sudo tee /proc/sys/net/ipv4/ip_forward
This works because the output redirection is deferred to the tee
command, which at that point does have root permissions because it was executed via sudo
.
sudo bash -c "echo 0 > /proc/sys/net/ipv4/ip_forward"
This works because the shell doing the redirection has root permissions.
1
Also, you might needsudo
for the command, but not for the file being output and the redirection works just fine:sudo foo-needs-privilege > /tmp/this-output-file-doesnt
– Dennis Williamson
2 days ago
add a comment |Â
up vote
11
down vote
Nitpick on @bertieb's answer that says 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.
There is no inherent limitation, only a misunderstanding of how the command is processed.
Example:
sudo echo 0 > /proc/sys/net/ipv4/ip_forward
The current shell parses the command line. It finds the output redirection and performs that. Then it executes the command, which is the sudo
and provides the remaining command line as arguments to the executed command. If the current shell does not have root permissions, then the output redirection will fail.
echo 0 | sudo tee /proc/sys/net/ipv4/ip_forward
This works because the output redirection is deferred to the tee
command, which at that point does have root permissions because it was executed via sudo
.
sudo bash -c "echo 0 > /proc/sys/net/ipv4/ip_forward"
This works because the shell doing the redirection has root permissions.
1
Also, you might needsudo
for the command, but not for the file being output and the redirection works just fine:sudo foo-needs-privilege > /tmp/this-output-file-doesnt
– Dennis Williamson
2 days ago
add a comment |Â
up vote
11
down vote
up vote
11
down vote
Nitpick on @bertieb's answer that says 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.
There is no inherent limitation, only a misunderstanding of how the command is processed.
Example:
sudo echo 0 > /proc/sys/net/ipv4/ip_forward
The current shell parses the command line. It finds the output redirection and performs that. Then it executes the command, which is the sudo
and provides the remaining command line as arguments to the executed command. If the current shell does not have root permissions, then the output redirection will fail.
echo 0 | sudo tee /proc/sys/net/ipv4/ip_forward
This works because the output redirection is deferred to the tee
command, which at that point does have root permissions because it was executed via sudo
.
sudo bash -c "echo 0 > /proc/sys/net/ipv4/ip_forward"
This works because the shell doing the redirection has root permissions.
Nitpick on @bertieb's answer that says 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.
There is no inherent limitation, only a misunderstanding of how the command is processed.
Example:
sudo echo 0 > /proc/sys/net/ipv4/ip_forward
The current shell parses the command line. It finds the output redirection and performs that. Then it executes the command, which is the sudo
and provides the remaining command line as arguments to the executed command. If the current shell does not have root permissions, then the output redirection will fail.
echo 0 | sudo tee /proc/sys/net/ipv4/ip_forward
This works because the output redirection is deferred to the tee
command, which at that point does have root permissions because it was executed via sudo
.
sudo bash -c "echo 0 > /proc/sys/net/ipv4/ip_forward"
This works because the shell doing the redirection has root permissions.
answered 2 days ago
studog
1437
1437
1
Also, you might needsudo
for the command, but not for the file being output and the redirection works just fine:sudo foo-needs-privilege > /tmp/this-output-file-doesnt
– Dennis Williamson
2 days ago
add a comment |Â
1
Also, you might needsudo
for the command, but not for the file being output and the redirection works just fine:sudo foo-needs-privilege > /tmp/this-output-file-doesnt
– Dennis Williamson
2 days ago
1
1
Also, you might need
sudo
for the command, but not for the file being output and the redirection works just fine: sudo foo-needs-privilege > /tmp/this-output-file-doesnt
– Dennis Williamson
2 days ago
Also, you might need
sudo
for the command, but not for the file being output and the redirection works just fine: sudo foo-needs-privilege > /tmp/this-output-file-doesnt
– Dennis Williamson
2 days ago
add a comment |Â
up vote
11
down vote
tee
is far from useless. I use it all the time and am glad it exists. It's a very useful tool if you have a pipeline that you want to split up. A very simple example is that you have some directory $d
that you want to tar and you also want to hash it because you're paranoid (like I am) and don't trust the storage medium to hold the data reliably. You could write it to the disk first and then hash it, but that'd fail if the archive gets corrupted before it's hashed. Furthermore, you'd have to read it and if you work on files that are several hundred GB in size a lot, you will know that you really don't want to read them again if it doesn't have to be.
So what I do is simply this:
tar -c "$d" | tee >(sha256sum) >(cat > "$d"".tar") > /dev/null
It creates the tar ball and pipes it to tee which then pipes it to two sub-shells, in one of which it's hashed and in the other of which it's written to the disk.
It's also great if you want to perform several operations on a big file:
< file.tar.gz tee >(sha256sum) >(tar -xz) /other/storage/location/file.tar.gz
Reads the file once, hashes it (so you can check whether it's still as it should be), extracts it, and copies it to a different location. No need to read it three times for that.
1
Nitpick:tee
does not create the subshells; the calling shell runssha5sum
andcat
and connects their output to file descriptors which are passed totee
. Also, a useless use ofcat
; you can use input redirection to havetee
read directly fromfile.tar.gz
.
– chepner
2 days ago
@chepner You're right about the first interjection but you're completely wrong about the second one. I like writing my pipelines in order, so denoting the input at the right is terrible for readability and doing so is clearly objectively inferior to my method and totally not a subjective preference of mine.cat
is love.cat
is life.
– UTF-8
2 days ago
5
You can also write< file.tar.gz tee >(sha256sum) ...
if you are concerned about the lexical ordering of the redirections. That doesn't change the fact that there is no need for an entirely separate process just to feed a single file totee
.
– chepner
2 days ago
1
@chepner Cool, thank you! Learned something today. :)
– UTF-8
2 days ago
Useless use ofdd
as well. Use/other/storage/location/file.tar.gz
as an arg totee
, so it writes to the file directly instead of to a pipe to another process. Same problem with the first example: you're gaining no readability at all by piping the output throughcat > "$d".tar
. Wait, you actually have the quotes on the".tar"
but the expansion of$d
is unquoted?!?)
– Peter Cordes
yesterday
 |Â
show 5 more comments
up vote
11
down vote
tee
is far from useless. I use it all the time and am glad it exists. It's a very useful tool if you have a pipeline that you want to split up. A very simple example is that you have some directory $d
that you want to tar and you also want to hash it because you're paranoid (like I am) and don't trust the storage medium to hold the data reliably. You could write it to the disk first and then hash it, but that'd fail if the archive gets corrupted before it's hashed. Furthermore, you'd have to read it and if you work on files that are several hundred GB in size a lot, you will know that you really don't want to read them again if it doesn't have to be.
So what I do is simply this:
tar -c "$d" | tee >(sha256sum) >(cat > "$d"".tar") > /dev/null
It creates the tar ball and pipes it to tee which then pipes it to two sub-shells, in one of which it's hashed and in the other of which it's written to the disk.
It's also great if you want to perform several operations on a big file:
< file.tar.gz tee >(sha256sum) >(tar -xz) /other/storage/location/file.tar.gz
Reads the file once, hashes it (so you can check whether it's still as it should be), extracts it, and copies it to a different location. No need to read it three times for that.
1
Nitpick:tee
does not create the subshells; the calling shell runssha5sum
andcat
and connects their output to file descriptors which are passed totee
. Also, a useless use ofcat
; you can use input redirection to havetee
read directly fromfile.tar.gz
.
– chepner
2 days ago
@chepner You're right about the first interjection but you're completely wrong about the second one. I like writing my pipelines in order, so denoting the input at the right is terrible for readability and doing so is clearly objectively inferior to my method and totally not a subjective preference of mine.cat
is love.cat
is life.
– UTF-8
2 days ago
5
You can also write< file.tar.gz tee >(sha256sum) ...
if you are concerned about the lexical ordering of the redirections. That doesn't change the fact that there is no need for an entirely separate process just to feed a single file totee
.
– chepner
2 days ago
1
@chepner Cool, thank you! Learned something today. :)
– UTF-8
2 days ago
Useless use ofdd
as well. Use/other/storage/location/file.tar.gz
as an arg totee
, so it writes to the file directly instead of to a pipe to another process. Same problem with the first example: you're gaining no readability at all by piping the output throughcat > "$d".tar
. Wait, you actually have the quotes on the".tar"
but the expansion of$d
is unquoted?!?)
– Peter Cordes
yesterday
 |Â
show 5 more comments
up vote
11
down vote
up vote
11
down vote
tee
is far from useless. I use it all the time and am glad it exists. It's a very useful tool if you have a pipeline that you want to split up. A very simple example is that you have some directory $d
that you want to tar and you also want to hash it because you're paranoid (like I am) and don't trust the storage medium to hold the data reliably. You could write it to the disk first and then hash it, but that'd fail if the archive gets corrupted before it's hashed. Furthermore, you'd have to read it and if you work on files that are several hundred GB in size a lot, you will know that you really don't want to read them again if it doesn't have to be.
So what I do is simply this:
tar -c "$d" | tee >(sha256sum) >(cat > "$d"".tar") > /dev/null
It creates the tar ball and pipes it to tee which then pipes it to two sub-shells, in one of which it's hashed and in the other of which it's written to the disk.
It's also great if you want to perform several operations on a big file:
< file.tar.gz tee >(sha256sum) >(tar -xz) /other/storage/location/file.tar.gz
Reads the file once, hashes it (so you can check whether it's still as it should be), extracts it, and copies it to a different location. No need to read it three times for that.
tee
is far from useless. I use it all the time and am glad it exists. It's a very useful tool if you have a pipeline that you want to split up. A very simple example is that you have some directory $d
that you want to tar and you also want to hash it because you're paranoid (like I am) and don't trust the storage medium to hold the data reliably. You could write it to the disk first and then hash it, but that'd fail if the archive gets corrupted before it's hashed. Furthermore, you'd have to read it and if you work on files that are several hundred GB in size a lot, you will know that you really don't want to read them again if it doesn't have to be.
So what I do is simply this:
tar -c "$d" | tee >(sha256sum) >(cat > "$d"".tar") > /dev/null
It creates the tar ball and pipes it to tee which then pipes it to two sub-shells, in one of which it's hashed and in the other of which it's written to the disk.
It's also great if you want to perform several operations on a big file:
< file.tar.gz tee >(sha256sum) >(tar -xz) /other/storage/location/file.tar.gz
Reads the file once, hashes it (so you can check whether it's still as it should be), extracts it, and copies it to a different location. No need to read it three times for that.
edited yesterday
answered 2 days ago


UTF-8
417312
417312
1
Nitpick:tee
does not create the subshells; the calling shell runssha5sum
andcat
and connects their output to file descriptors which are passed totee
. Also, a useless use ofcat
; you can use input redirection to havetee
read directly fromfile.tar.gz
.
– chepner
2 days ago
@chepner You're right about the first interjection but you're completely wrong about the second one. I like writing my pipelines in order, so denoting the input at the right is terrible for readability and doing so is clearly objectively inferior to my method and totally not a subjective preference of mine.cat
is love.cat
is life.
– UTF-8
2 days ago
5
You can also write< file.tar.gz tee >(sha256sum) ...
if you are concerned about the lexical ordering of the redirections. That doesn't change the fact that there is no need for an entirely separate process just to feed a single file totee
.
– chepner
2 days ago
1
@chepner Cool, thank you! Learned something today. :)
– UTF-8
2 days ago
Useless use ofdd
as well. Use/other/storage/location/file.tar.gz
as an arg totee
, so it writes to the file directly instead of to a pipe to another process. Same problem with the first example: you're gaining no readability at all by piping the output throughcat > "$d".tar
. Wait, you actually have the quotes on the".tar"
but the expansion of$d
is unquoted?!?)
– Peter Cordes
yesterday
 |Â
show 5 more comments
1
Nitpick:tee
does not create the subshells; the calling shell runssha5sum
andcat
and connects their output to file descriptors which are passed totee
. Also, a useless use ofcat
; you can use input redirection to havetee
read directly fromfile.tar.gz
.
– chepner
2 days ago
@chepner You're right about the first interjection but you're completely wrong about the second one. I like writing my pipelines in order, so denoting the input at the right is terrible for readability and doing so is clearly objectively inferior to my method and totally not a subjective preference of mine.cat
is love.cat
is life.
– UTF-8
2 days ago
5
You can also write< file.tar.gz tee >(sha256sum) ...
if you are concerned about the lexical ordering of the redirections. That doesn't change the fact that there is no need for an entirely separate process just to feed a single file totee
.
– chepner
2 days ago
1
@chepner Cool, thank you! Learned something today. :)
– UTF-8
2 days ago
Useless use ofdd
as well. Use/other/storage/location/file.tar.gz
as an arg totee
, so it writes to the file directly instead of to a pipe to another process. Same problem with the first example: you're gaining no readability at all by piping the output throughcat > "$d".tar
. Wait, you actually have the quotes on the".tar"
but the expansion of$d
is unquoted?!?)
– Peter Cordes
yesterday
1
1
Nitpick:
tee
does not create the subshells; the calling shell runs sha5sum
and cat
and connects their output to file descriptors which are passed to tee
. Also, a useless use of cat
; you can use input redirection to have tee
read directly from file.tar.gz
.– chepner
2 days ago
Nitpick:
tee
does not create the subshells; the calling shell runs sha5sum
and cat
and connects their output to file descriptors which are passed to tee
. Also, a useless use of cat
; you can use input redirection to have tee
read directly from file.tar.gz
.– chepner
2 days ago
@chepner You're right about the first interjection but you're completely wrong about the second one. I like writing my pipelines in order, so denoting the input at the right is terrible for readability and doing so is clearly objectively inferior to my method and totally not a subjective preference of mine.
cat
is love. cat
is life.– UTF-8
2 days ago
@chepner You're right about the first interjection but you're completely wrong about the second one. I like writing my pipelines in order, so denoting the input at the right is terrible for readability and doing so is clearly objectively inferior to my method and totally not a subjective preference of mine.
cat
is love. cat
is life.– UTF-8
2 days ago
5
5
You can also write
< file.tar.gz tee >(sha256sum) ...
if you are concerned about the lexical ordering of the redirections. That doesn't change the fact that there is no need for an entirely separate process just to feed a single file to tee
.– chepner
2 days ago
You can also write
< file.tar.gz tee >(sha256sum) ...
if you are concerned about the lexical ordering of the redirections. That doesn't change the fact that there is no need for an entirely separate process just to feed a single file to tee
.– chepner
2 days ago
1
1
@chepner Cool, thank you! Learned something today. :)
– UTF-8
2 days ago
@chepner Cool, thank you! Learned something today. :)
– UTF-8
2 days ago
Useless use of
dd
as well. Use /other/storage/location/file.tar.gz
as an arg to tee
, so it writes to the file directly instead of to a pipe to another process. Same problem with the first example: you're gaining no readability at all by piping the output through cat > "$d".tar
. Wait, you actually have the quotes on the ".tar"
but the expansion of $d
is unquoted?!?)– Peter Cordes
yesterday
Useless use of
dd
as well. Use /other/storage/location/file.tar.gz
as an arg to tee
, so it writes to the file directly instead of to a pipe to another process. Same problem with the first example: you're gaining no readability at all by piping the output through cat > "$d".tar
. Wait, you actually have the quotes on the ".tar"
but the expansion of $d
is unquoted?!?)– Peter Cordes
yesterday
 |Â
show 5 more comments
up vote
7
down vote
This is a tee:
A T-shaped pipe fitting. It has an inlet, and two separate outlets.
In other words, it splits one pipe into two; like a fork in the road.
Similarly, tee
is a pipe (|
) that allows you to redirect your standard input to two separate output locations.
Example
Say for instance, you type ls /
.
You'll get an output that looks something like:
Applications Network Users bin dev net private tmp var
Library System Volumes cores etc home opt sbin usr
Redirect the output to a text file, ls / > ls.txt
, and no output is displayed in the shell, only in the resulting text file.
Want to see the output, AND pass it to a text file at the same time?
Add a tee
to your pipe (|
) ie: ls / | tee ls.txt
Compare the two:
ls / > ls.txt
ls / | tee ls.txt
add a comment |Â
up vote
7
down vote
This is a tee:
A T-shaped pipe fitting. It has an inlet, and two separate outlets.
In other words, it splits one pipe into two; like a fork in the road.
Similarly, tee
is a pipe (|
) that allows you to redirect your standard input to two separate output locations.
Example
Say for instance, you type ls /
.
You'll get an output that looks something like:
Applications Network Users bin dev net private tmp var
Library System Volumes cores etc home opt sbin usr
Redirect the output to a text file, ls / > ls.txt
, and no output is displayed in the shell, only in the resulting text file.
Want to see the output, AND pass it to a text file at the same time?
Add a tee
to your pipe (|
) ie: ls / | tee ls.txt
Compare the two:
ls / > ls.txt
ls / | tee ls.txt
add a comment |Â
up vote
7
down vote
up vote
7
down vote
This is a tee:
A T-shaped pipe fitting. It has an inlet, and two separate outlets.
In other words, it splits one pipe into two; like a fork in the road.
Similarly, tee
is a pipe (|
) that allows you to redirect your standard input to two separate output locations.
Example
Say for instance, you type ls /
.
You'll get an output that looks something like:
Applications Network Users bin dev net private tmp var
Library System Volumes cores etc home opt sbin usr
Redirect the output to a text file, ls / > ls.txt
, and no output is displayed in the shell, only in the resulting text file.
Want to see the output, AND pass it to a text file at the same time?
Add a tee
to your pipe (|
) ie: ls / | tee ls.txt
Compare the two:
ls / > ls.txt
ls / | tee ls.txt
This is a tee:
A T-shaped pipe fitting. It has an inlet, and two separate outlets.
In other words, it splits one pipe into two; like a fork in the road.
Similarly, tee
is a pipe (|
) that allows you to redirect your standard input to two separate output locations.
Example
Say for instance, you type ls /
.
You'll get an output that looks something like:
Applications Network Users bin dev net private tmp var
Library System Volumes cores etc home opt sbin usr
Redirect the output to a text file, ls / > ls.txt
, and no output is displayed in the shell, only in the resulting text file.
Want to see the output, AND pass it to a text file at the same time?
Add a tee
to your pipe (|
) ie: ls / | tee ls.txt
Compare the two:
ls / > ls.txt
ls / | tee ls.txt
answered yesterday


tjt263
1,0492931
1,0492931
add a comment |Â
add a comment |Â
up vote
6
down vote
The most common use of tee is to see the text on the terminal at the same time you send it to the file (or files). The wording of your question assumes you only ever write text to logfiles. I have scripts which write lists of filenames or directory names to trigger files (to be processed by other scripts asynchronously) and I use tee to send the same content to stdout. All stdout is directed to the logs. So I have my text where I want it and I have a log entry recording that I did this, all from a single 'echo' statement
tee is also the best method in Unix for making multiple identical files. I use it occasionally for making multiple empty files, like this ...
:|tee file01 file02 file03
New contributor
Wil Young is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5
why nottouch
? (more immediately obvious what is happening)
– Attie
2 days ago
add a comment |Â
up vote
6
down vote
The most common use of tee is to see the text on the terminal at the same time you send it to the file (or files). The wording of your question assumes you only ever write text to logfiles. I have scripts which write lists of filenames or directory names to trigger files (to be processed by other scripts asynchronously) and I use tee to send the same content to stdout. All stdout is directed to the logs. So I have my text where I want it and I have a log entry recording that I did this, all from a single 'echo' statement
tee is also the best method in Unix for making multiple identical files. I use it occasionally for making multiple empty files, like this ...
:|tee file01 file02 file03
New contributor
Wil Young is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5
why nottouch
? (more immediately obvious what is happening)
– Attie
2 days ago
add a comment |Â
up vote
6
down vote
up vote
6
down vote
The most common use of tee is to see the text on the terminal at the same time you send it to the file (or files). The wording of your question assumes you only ever write text to logfiles. I have scripts which write lists of filenames or directory names to trigger files (to be processed by other scripts asynchronously) and I use tee to send the same content to stdout. All stdout is directed to the logs. So I have my text where I want it and I have a log entry recording that I did this, all from a single 'echo' statement
tee is also the best method in Unix for making multiple identical files. I use it occasionally for making multiple empty files, like this ...
:|tee file01 file02 file03
New contributor
Wil Young is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The most common use of tee is to see the text on the terminal at the same time you send it to the file (or files). The wording of your question assumes you only ever write text to logfiles. I have scripts which write lists of filenames or directory names to trigger files (to be processed by other scripts asynchronously) and I use tee to send the same content to stdout. All stdout is directed to the logs. So I have my text where I want it and I have a log entry recording that I did this, all from a single 'echo' statement
tee is also the best method in Unix for making multiple identical files. I use it occasionally for making multiple empty files, like this ...
:|tee file01 file02 file03
New contributor
Wil Young is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Wil Young is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 2 days ago
Wil Young
612
612
New contributor
Wil Young is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Wil Young is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Wil Young is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5
why nottouch
? (more immediately obvious what is happening)
– Attie
2 days ago
add a comment |Â
5
why nottouch
? (more immediately obvious what is happening)
– Attie
2 days ago
5
5
why not
touch
? (more immediately obvious what is happening)– Attie
2 days ago
why not
touch
? (more immediately obvious what is happening)– Attie
2 days ago
add a comment |Â
up vote
6
down vote
As other people have mentioned, piping output to the tee
command writes that output to both a file and to stdout.
I often use tee
when I want to capture output from a command that takes a long time to run, while also wanting to visually inspect the output as the command makes it available. That way, I don't have to wait for the command to finish running before I inspect the output.
What doesn't seem to have been mentioned yet (unless I missed it), is that the tee
command can also write to multiple files at once. For example:
ls *.png | tee a.txt b.txt
will write out all the *.png
files in the current directory to two different files (a.txt
and b.txt
) at once.
In fact, you can type text to several different files at once with tee
like this:
$ tee --append a.txt b.txt c.txt d.txt
These lines are appended to four different files,
and are also written to stdout.
CTRL-D
New contributor
J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
6
down vote
As other people have mentioned, piping output to the tee
command writes that output to both a file and to stdout.
I often use tee
when I want to capture output from a command that takes a long time to run, while also wanting to visually inspect the output as the command makes it available. That way, I don't have to wait for the command to finish running before I inspect the output.
What doesn't seem to have been mentioned yet (unless I missed it), is that the tee
command can also write to multiple files at once. For example:
ls *.png | tee a.txt b.txt
will write out all the *.png
files in the current directory to two different files (a.txt
and b.txt
) at once.
In fact, you can type text to several different files at once with tee
like this:
$ tee --append a.txt b.txt c.txt d.txt
These lines are appended to four different files,
and are also written to stdout.
CTRL-D
New contributor
J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
6
down vote
up vote
6
down vote
As other people have mentioned, piping output to the tee
command writes that output to both a file and to stdout.
I often use tee
when I want to capture output from a command that takes a long time to run, while also wanting to visually inspect the output as the command makes it available. That way, I don't have to wait for the command to finish running before I inspect the output.
What doesn't seem to have been mentioned yet (unless I missed it), is that the tee
command can also write to multiple files at once. For example:
ls *.png | tee a.txt b.txt
will write out all the *.png
files in the current directory to two different files (a.txt
and b.txt
) at once.
In fact, you can type text to several different files at once with tee
like this:
$ tee --append a.txt b.txt c.txt d.txt
These lines are appended to four different files,
and are also written to stdout.
CTRL-D
New contributor
J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
As other people have mentioned, piping output to the tee
command writes that output to both a file and to stdout.
I often use tee
when I want to capture output from a command that takes a long time to run, while also wanting to visually inspect the output as the command makes it available. That way, I don't have to wait for the command to finish running before I inspect the output.
What doesn't seem to have been mentioned yet (unless I missed it), is that the tee
command can also write to multiple files at once. For example:
ls *.png | tee a.txt b.txt
will write out all the *.png
files in the current directory to two different files (a.txt
and b.txt
) at once.
In fact, you can type text to several different files at once with tee
like this:
$ tee --append a.txt b.txt c.txt d.txt
These lines are appended to four different files,
and are also written to stdout.
CTRL-D
New contributor
J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 2 days ago
J-L
1611
1611
New contributor
J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
up vote
0
down vote
Imagine, you want to write the output of a command to a log file AND print to stdout. When you need to do it at the same time, then you need tee
.
A use case is to have build scripts that write the whole build to stdout (e.g. for Jenkins) but important stuff at the same time to a separate log file (for summary emails).
You'll really start missing tee
when you have to script in Windows. There is no tee
and that is really annoying.
Isn't it trivial to create?
– Lightness Races in Orbit
yesterday
It is not possible with batch/cmd as you can not split a stream of output from a command easily.
– domih
15 hours ago
Right but like a three-line C++ program...
– Lightness Races in Orbit
15 hours ago
The Windows unxutils distribution has many Unix command line tools which, unlike some distributions, do not pollute your Windows execution environment. The biggest limitation is on "glob"bing, which works differently on Unix/Linux than on Windows. "tee" is among the tools available.
– cmm
11 hours ago
add a comment |Â
up vote
0
down vote
Imagine, you want to write the output of a command to a log file AND print to stdout. When you need to do it at the same time, then you need tee
.
A use case is to have build scripts that write the whole build to stdout (e.g. for Jenkins) but important stuff at the same time to a separate log file (for summary emails).
You'll really start missing tee
when you have to script in Windows. There is no tee
and that is really annoying.
Isn't it trivial to create?
– Lightness Races in Orbit
yesterday
It is not possible with batch/cmd as you can not split a stream of output from a command easily.
– domih
15 hours ago
Right but like a three-line C++ program...
– Lightness Races in Orbit
15 hours ago
The Windows unxutils distribution has many Unix command line tools which, unlike some distributions, do not pollute your Windows execution environment. The biggest limitation is on "glob"bing, which works differently on Unix/Linux than on Windows. "tee" is among the tools available.
– cmm
11 hours ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Imagine, you want to write the output of a command to a log file AND print to stdout. When you need to do it at the same time, then you need tee
.
A use case is to have build scripts that write the whole build to stdout (e.g. for Jenkins) but important stuff at the same time to a separate log file (for summary emails).
You'll really start missing tee
when you have to script in Windows. There is no tee
and that is really annoying.
Imagine, you want to write the output of a command to a log file AND print to stdout. When you need to do it at the same time, then you need tee
.
A use case is to have build scripts that write the whole build to stdout (e.g. for Jenkins) but important stuff at the same time to a separate log file (for summary emails).
You'll really start missing tee
when you have to script in Windows. There is no tee
and that is really annoying.
answered yesterday


domih
1156
1156
Isn't it trivial to create?
– Lightness Races in Orbit
yesterday
It is not possible with batch/cmd as you can not split a stream of output from a command easily.
– domih
15 hours ago
Right but like a three-line C++ program...
– Lightness Races in Orbit
15 hours ago
The Windows unxutils distribution has many Unix command line tools which, unlike some distributions, do not pollute your Windows execution environment. The biggest limitation is on "glob"bing, which works differently on Unix/Linux than on Windows. "tee" is among the tools available.
– cmm
11 hours ago
add a comment |Â
Isn't it trivial to create?
– Lightness Races in Orbit
yesterday
It is not possible with batch/cmd as you can not split a stream of output from a command easily.
– domih
15 hours ago
Right but like a three-line C++ program...
– Lightness Races in Orbit
15 hours ago
The Windows unxutils distribution has many Unix command line tools which, unlike some distributions, do not pollute your Windows execution environment. The biggest limitation is on "glob"bing, which works differently on Unix/Linux than on Windows. "tee" is among the tools available.
– cmm
11 hours ago
Isn't it trivial to create?
– Lightness Races in Orbit
yesterday
Isn't it trivial to create?
– Lightness Races in Orbit
yesterday
It is not possible with batch/cmd as you can not split a stream of output from a command easily.
– domih
15 hours ago
It is not possible with batch/cmd as you can not split a stream of output from a command easily.
– domih
15 hours ago
Right but like a three-line C++ program...
– Lightness Races in Orbit
15 hours ago
Right but like a three-line C++ program...
– Lightness Races in Orbit
15 hours ago
The Windows unxutils distribution has many Unix command line tools which, unlike some distributions, do not pollute your Windows execution environment. The biggest limitation is on "glob"bing, which works differently on Unix/Linux than on Windows. "tee" is among the tools available.
– cmm
11 hours ago
The Windows unxutils distribution has many Unix command line tools which, unlike some distributions, do not pollute your Windows execution environment. The biggest limitation is on "glob"bing, which works differently on Unix/Linux than on Windows. "tee" is among the tools available.
– cmm
11 hours ago
add a comment |Â
R Moog is a new contributor. Be nice, and check out our Code of Conduct.
R Moog is a new contributor. Be nice, and check out our Code of Conduct.
R Moog is a new contributor. Be nice, and check out our Code of Conduct.
R Moog is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1356841%2fwhat-is-the-purpose-of-tee%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
17
How was this not answered by the very first line of the man page "...and write to standard output and files"? The answers are interesting, but broadly talking about how pipes are useful just reinforces how this Q seems too broad, and should perhaps have been closed.
– Xen2050
23 hours ago