The tee
command in Bash is used to read from standard input and write to standard output and one or more files simultaneously. This allows you to view the output of a command while also saving it to a file.
The basic syntax of the tee
command is as follows:
tee [options] [arguments]
-a
, --append
: Append the output to the given files instead of overwriting them.-i
, --ignore-interrupts
: Ignore interrupt signals.--help
: Display help information about the command.--version
: Show the version information of the command.echo "Hello, World!" | tee output.txt
echo "Another line" | tee -a output.txt
echo "Logging data" | tee file1.txt file2.txt
tee
with other commands in a pipeline.
ls -l | tee directory_listing.txt | grep ".txt"
echo "This will not be interrupted" | tee -i output.txt
-a
option when you want to keep adding data to a file without losing the existing content.tee
with other commands in a pipeline to capture intermediate output for debugging or logging purposes.tee
will overwrite files by default, so use the -a
option if you want to append instead.