Linux print to STDOUT and redirect to a file using a single command

Is there a way to both track the output of the command to the terminal and redirect the file to a single file, and not use two separate commands in csh (for historical reasons, I should use csh for this purpose). I'm currently doing this

echo "Hello World!" echo "Hello World!" > textfile echo "next line blah blah" echo "next line blah blah" >> textfile 
+4
source share
1 answer

This is exactly what tee for:

 echo "Hello World!" | tee textfile 

For multiple outputs you can use

 ( echo "Hello World!" echo "next line blah blah" ) | tee textfile 

or use the append parameter with tee .

 echo "Hello World!" | tee textfile echo "next line blah blah" | tee -a textfile 
+7
source

All Articles