In this article, we will be discussing the useful cases of tee unix command with examples.
tee – Used in the middle of a pipeline, this command allows you to both redirect output to a file, and pass it to further commands in the pipeline.
How to use tee command
Examples: $check_patch_logs.ksh | tee check.log| more
Output of check_patch_logs.ksh is stored in the filecheck.log, and also pass it to more to display it one screen at a time.
-a option with tee command
By default tee command overwrites the file.
ls | tee x.txt
The above command will overwrite the file x.txt of it exists
You can instruct tee command to append to the file using the option –a
ls | tee -a x.txt
Now this will create new file x.txt if it does not exists, if it exists, it will append to it
How to use tee to write to multiple files
We just need to specify the files name
ls | tee x.txt x1.txt x2.txt
it will store the output of ls in all these files.
awk command : Complete guide on awk command in Unix with lot of examples
sed command : A good overview of sed command and difference between awk and sed and much more
grep command : A lot of grep command with options
windows grep equivalent: Grep equivalent in window OS
tr command in Unix
gzip and gunzip command in Linux