tee Command: Tutorial & Examples
Chaining together standard input and output
tee command in Linux is a command-line utility that is used to chain together standard input
and standard output in a way that allows you to write to one or more files while also viewing the output on your
terminal. This is typically done by piping the output of a command to
tee, which then writes that
output to a file and also sends it to the standard output.
tee command is extremely useful when you want to log the output of a command, but also want to see the output in
real time. It's also frequently used in scripts and automations where logging is important.
Common Usage of
tee command is typically used in conjunction with other commands, using a pipe (
|) to direct the output of the
preceding command to
Here is a basic example of how to use the
echo "Hello, World!" | tee hello.txt
In this example,
echo outputs the text "Hello, World!", which is then piped to
command writes the output to the file
hello.txt and also displays it on the terminal.
tee command has several parameters that modify its behavior:
-a: Appends the output to the files rather than overwriting them.
-i: Ignores interrupts.
Here is an example of using the
echo "Hello again, World!" | tee -a hello.txt
In this example, the text "Hello again, World!" is added to the end of
hello.txt rather than overwriting the existing
tee command with other commands
tee command is very powerful when combined with other commands. For example, you can use
ls command to write a list of files in a directory to a file while also displaying the list
on the terminal:
ls | tee filelist.txt
tee command is a powerful tool in your Linux command line toolbox. It allows you to write the output of a command
to one or more files while also displaying the output on your terminal. This makes it a valuable tool for logging and
troubleshooting. It's definitely a command that every Linux user should become familiar with.