The tee command in Linux is used to read from standard input and write to both standard output and one or more files simultaneously. It allows you to view the output on the terminal while also saving it to a file.
Syntax:
command | tee [options] file_name
By default, tee overwrites the content of the file. To append data instead, use the -a option.
Examples:
1. Basic usage:
echo “Hello World” | tee file.txt
This will print “Hello World” to the terminal and save it to file.txt.
2. Appending to a file:
echo “New line” | tee -a file.txt
This will append “New line” to file.txt and display it on the terminal.
The tee command is useful for logging, debugging, and when you need to capture command output while still viewing it.