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 : Awk command in Unix or Linux is a powerful command for processing text. Learn about awk syntax, records, fields, line Separator with examples of awk in unix
sed command : sed command is a Stream Editor – works as a filter processing input line by line And here are 32 Useful sed command examples in Linux/Unix
grep command : Grep command Means – globally search regular expression.grep command in unix is used for searching text,regular expression across multiple files
windows grep equivalent: windows grep equivalent to search text: Find | findstr | power select-string. Detailed explanation with lots of example for easy understanding
tr command in Unix: Check out about tee command in Unix,what options are available, how to append file using tee command, how to write to multiple files
gzip and gunzip command in Linux