Hi, this is Sandra Henry-Stocker, author of
the “Unix as a Second Language” blog on NetworkWorld.
In this Linux tip, we’re going to look at the tee command. It’s a very simple command
that allows you to run some other command and send its output both to the screen and
to a file at the same time. Here’s a very simple example:
There, we see the output of the who command on the screen. Now let’s check out the output
of the file that was just created. Tee saves you the trouble of having to copy
and paste text from your screen in order to save it in a file.
One important thing to consider is that the tee command will overwrite the file if a file
by that name already exists. If you want, instead, to append the new output to an existing
file, use the -a (append) option like this: If you look at the file, you’ll then see
something like this: If it’s helpful, you can even get the tee
command to send your output to multiple files. All you need to do is list the files sequentially
like this: If you want to append output to multiple files,
do the same, but add the -a option. Here, we’re appending the current date and time
to the three files we created in the previous command.
That’s your Linux tip for the tee command. If you have questions or would like to suggest
a topic, please add a comment below. And don’t forget to subscribe to the IDG Tech(talk)
channel on YouTube. If you liked this video, please hit the like
and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and