tee

Someone recently advised me to use the tee command to write to standard out.

Why would you pipe your commands to
tee -a <filename>
rather than just using
>> <filename>
?

For example:

date|tee -a myfile

seems to be the same as

date >> myfile

Is there a benefit to using tee that I'm not seeing?

Thanks,

Darin

When you need to write a log and put the same data to the tty, then tee is useful.

Plus

date > t.lis

does not write anything to the tty. All stdout output goes into the file.

A best use of tee is:

command 2&>1 | tee -a somelog.file

To capture both errors and normal output. This way the person running the script sees what happened. Then support has a log file to refer to as well.

ok. But can't you do the same thing with

command >> somelog.file 2/&1

?

I think you missed the main point of Jim's statement:

Tee will write to the file and copy the output to the screen.

If you want to write to the file, and not see the output then don't use tee, otherwise do.

Ok. Thanks. That helps me.

mysql -uroot -pPassWord --tee='/root/myquery.txt'

I do always use tee while accessing Mysql database. This helps me to check the output of a sql command when I can not browse the earlier pages using "Page Up".