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.txtecho "-----"ls -l | grep fileecho "-----"cat file.txt