LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 08-17-2006, 04:19 PM   #1
trewsfan
LQ Newbie
 
Registered: Jul 2005
Posts: 13

Rep: Reputation: 0
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?
 
Old 08-17-2006, 04:22 PM   #2
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 3,513

Rep: Reputation: 63
date ; date >> outputfile.txt
 
Old 08-17-2006, 04:30 PM   #3
trewsfan
LQ Newbie
 
Registered: Jul 2005
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks, but that's not the same output. That's running two commands one after the other.

Last edited by trewsfan; 08-17-2006 at 04:35 PM.
 
Old 08-17-2006, 04:47 PM   #4
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 3,513

Rep: Reputation: 63
What the milliseconds are going to matter date only resolves to the second anyways your never going to see a difference.
 
Old 08-17-2006, 05:02 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,267

Rep: Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027
Simply pipe the output to tee - exactly what it was designed for.
manpage.
 
Old 08-17-2006, 05:09 PM   #6
trewsfan
LQ Newbie
 
Registered: Jul 2005
Posts: 13

Original Poster
Rep: Reputation: 0
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$
 
Old 08-17-2006, 05:25 PM   #7
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 3,513

Rep: Reputation: 63
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.

Last edited by HappyTux; 08-17-2006 at 05:26 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
program console output using C xrado Programming 5 04-04-2005 02:48 PM
the sound gives output when using mic but no output when run a music file medo Debian 0 04-19-2004 07:17 PM
noob needs help with console output (c++) shadow.blue Programming 7 04-19-2004 05:24 PM
Console output to X? dcm1878 Linux - Software 4 04-23-2003 08:07 PM
Long console output Loke Linux - Newbie 1 02-26-2003 06:35 AM


All times are GMT -5. The time now is 10:13 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration