What is the tee command in Linux?

The tee command in Linux reads the standard input and writes it to one or more files, along with the standard output.

Syntax

tee [OPTIONS] FILES...

Below are a few options that can be used.

Option Description
-a Appends to a file
-v Displays version information
--help Displays the command description and options

Code

In the code below, we use the tee command to redirect the output of the echo command to the file as well as to the terminal. Then, we use the grep command to check if the file is created. Finally, we print the contents of the file created by the tee command.

echo "hello-educative" | tee file.txt
echo "-----"
ls -l | grep file
echo "-----"
cat file.txt
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources