Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
04-02-2011, 02:17 PM
|
#16
|
|
LQ Newbie
Registered: Feb 2011
Location: Hartlepool
Distribution: Mint
Posts: 13
Rep:
|
O.K. I've got the gist of this, but I can't see how to append the output to an existing file. Is that possible?
|
|
|
|
04-02-2011, 02:43 PM
|
#17
|
|
Member
Registered: May 2005
Location: St. Louis, MO
Distribution: CentOS6
Posts: 256
Rep:
|
Append by using the -a option to tee:
Code:
drf@maplepark ~]$ echo 'Output from echo' >archivefile
[drf@maplepark ~]$ echo 'Output from subsequent file run' |tee -a archivefile
Output from subsequent file run
[drf@maplepark ~]$ cat archivefile
Output from echo
Output from subsequent file run
[drf@maplepark ~]$
Last edited by david1941; 04-02-2011 at 02:43 PM.
Reason: fix code tags
|
|
|
2 members found this post helpful.
|
04-03-2011, 02:02 PM
|
#18
|
|
LQ Newbie
Registered: Feb 2011
Location: Hartlepool
Distribution: Mint
Posts: 13
Rep:
|
Got it! Thanks Dave
|
|
|
|
04-21-2011, 04:34 PM
|
#19
|
|
LQ Newbie
Registered: Jun 2010
Location: NYC
Distribution: Debian
Posts: 4
Rep:
|
thanks all
I'm now using pretty correctly all this commands/info/redirection
And for what I looked for a long time:
STDOUT + STDERR in a log file + on screen.
Quote:
exec 2>&1
exec > >(tee -a $LOG)
|
Works like a charm!
|
|
|
1 members found this post helpful.
|
11-11-2011, 01:15 PM
|
#20
|
|
Member
Registered: Apr 2002
Location: Houston Texas
Distribution: Debian / Gentoo / RHEL
Posts: 209
Rep:
|
Works
Nice, works perfectly. I have been searching for quite a while to figure that one out. Never been a big deal so I did not find the time dive deep.
<command> 2>&1 | tee -a logfile
|
|
|
|
03-23-2012, 04:34 AM
|
#21
|
|
LQ Newbie
Registered: Mar 2012
Posts: 1
Rep: 
|
hi everyone,
i have a question about how could i redirect the output to file renamed by time, for example 20120323.log
we have seen a redirect as "script > file.txt" but the name of this output is always the same "file.txt", we could define a output name with date?
is possible do it? and... how?
Last edited by aghabriel; 03-23-2012 at 04:37 AM.
|
|
|
|
03-23-2012, 06:04 AM
|
#22
|
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian Squeeze (server), Slackware 13.37 (netbook), Slackware64 14.0 (desktop),
Posts: 8,357
|
Quote:
Originally Posted by aghabriel
hi everyone,
i have a question about how could i redirect the output to file renamed by time, for example 20120323.log
we have seen a redirect as "script > file.txt" but the name of this output is always the same "file.txt", we could define a output name with date?
is possible do it? and... how?
|
Please start a new thread
|
|
|
|
04-06-2012, 07:28 AM
|
#23
|
|
LQ Newbie
Registered: Mar 2012
Posts: 3
Rep: 
|
Thank you for much needed information....
Now, what I actually want is to Append the file each time I run a command. I have already tried this but...
Code:
$ ls >> file |tee file
|
|
|
|
04-08-2012, 10:22 AM
|
#24
|
|
Member
Registered: Sep 2008
Distribution: Ubuntu 8.04 LTS Server
Posts: 84
Rep:
|
Quote:
Originally Posted by rahulu123
Thank you for much needed information....
Now, what I actually want is to Append the file each time I run a command. I have already tried this but...
Code:
$ ls >> file |tee file
|
This is more complicated than it looks at the first glance and you should check man bash to understand better how it works. First, | "assigns" stdout of ls to stdin of tee (see "pipeline" and then "redirection" in man bash). Then, stdout of ls is "assigned" to file (leaving stdin of tee with no input at all), so ls fills file with the list of files. Then, stdout of tee is copied to file, too. Tee receives nothing on its stdin, so it writes an empty file over file before you get any chance to read the file file.
You may want to try:
if you want to append the list of files to file and to display it on screen at the same time.
If you have nothing better to do, you can also have fun with:
Code:
ls > >(tee -a file)
and:
tee -a file < <(ls)
Last edited by doru; 04-08-2012 at 10:48 AM.
|
|
|
|
04-10-2012, 08:00 AM
|
#25
|
|
LQ Newbie
Registered: Mar 2012
Posts: 3
Rep: 
|
Quote:
You may want to try:
Code:
if you want to append the list of files to file and to display it on screen at the same time.
|
Worked perfectly, Thanks doru 
|
|
|
|
07-02-2012, 06:12 PM
|
#26
|
|
LQ Newbie
Registered: May 2012
Location: Germany
Posts: 4
Rep: 
|
What if i redirect into a file (ls -l > log.txt) and want it to show in realtime on another console (as if the command would run locally)? 'Cat log.txt' does only show a momentary snapshot. But it should permanently put out new data once appended/logged. An example would be 'tcpdump -i eth0 -n > log.txt'.
Edit: Got it. It's 'tail -f log.txt'
Last edited by BeachHead; 07-02-2012 at 06:22 PM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:00 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|