LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can I output to both console and a file? (http://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-output-to-both-console-and-a-file-474889/)

trewsfan 08-17-2006 04:19 PM

How can I output to both console and a file?
 
Suppose I am in a terminal.

Running: $ date
-> outputs the date to the terminal

Running: $ date >> outputfile.txt
-> outputs the date to the file outputfile.txt

What's the easiest way to send the same output to both the terminal and to the file?

HappyTux 08-17-2006 04:22 PM

date ; date >> outputfile.txt

trewsfan 08-17-2006 04:30 PM

Thanks, but that's not the same output. That's running two commands one after the other.

HappyTux 08-17-2006 04:47 PM

What the milliseconds are going to matter date only resolves to the second anyways your never going to see a difference.

syg00 08-17-2006 05:02 PM

Simply pipe the output to tee - exactly what it was designed for.
manpage.

trewsfan 08-17-2006 05:09 PM

Tee is exactly what I needed. Thanks.

Tux, it's because I'm not using this for the date command. I wanted it for the rsync command which has very different outputs when run consecutively.

:)

Example of how to use tee:

tyler@pago:~/simple$ ls
tyler@pago:~/simple$ date | tee output.txt
Thu Aug 17 17:06:46 CDT 2006
tyler@pago:~/simple$ ls
output.txt
tyler@pago:~/simple$ cat output.txt
Thu Aug 17 17:06:46 CDT 2006
tyler@pago:~/simple$

HappyTux 08-17-2006 05:25 PM

Quote:

Originally Posted by trewsfan
Tee is exactly what I needed. Thanks.

Tux, it's because I'm not using this for the date command. I wanted it for the rsync command which has very different outputs when run consecutively.

:)

Example of how to use tee:

tyler@pago:~/simple$ ls
tyler@pago:~/simple$ date | tee output.txt
Thu Aug 17 17:06:46 CDT 2006
tyler@pago:~/simple$ ls
output.txt
tyler@pago:~/simple$ cat output.txt
Thu Aug 17 17:06:46 CDT 2006
tyler@pago:~/simple$

Ah I see was kinda wondering why it mattered for a simple date command.

Edit: Your going to want tee -a then for the example you first gave but I would image you have read the man page and discovery this anyways.


All times are GMT -5. The time now is 07:26 AM.