LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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

Reply
 
Search this Thread
Old 04-02-2011, 03:17 PM   #16
Fitch
LQ Newbie
 
Registered: Feb 2011
Location: Hartlepool
Distribution: Mint
Posts: 14

Rep: Reputation: 1

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?
 
Old 04-02-2011, 03:43 PM   #17
david1941
Member
 
Registered: May 2005
Location: St. Louis, MO
Distribution: CentOS6
Posts: 267

Rep: Reputation: 57
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 03:43 PM. Reason: fix code tags
 
2 members found this post helpful.
Old 04-03-2011, 03:02 PM   #18
Fitch
LQ Newbie
 
Registered: Feb 2011
Location: Hartlepool
Distribution: Mint
Posts: 14

Rep: Reputation: 1
Got it! Thanks Dave
 
Old 04-21-2011, 05:34 PM   #19
4L3X
LQ Newbie
 
Registered: Jun 2010
Location: NYC
Distribution: Debian
Posts: 4

Rep: Reputation: 1
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.
Old 11-11-2011, 02:15 PM   #20
MrJoshua
Member
 
Registered: Apr 2002
Location: Houston Texas
Distribution: Debian / Gentoo / RHEL
Posts: 209

Rep: Reputation: 31
Thumbs up 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
 
Old 03-23-2012, 05:34 AM   #21
aghabriel
LQ Newbie
 
Registered: Mar 2012
Posts: 1

Rep: Reputation: Disabled
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 05:37 AM.
 
Old 03-23-2012, 07:04 AM   #22
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,557
Blog Entries: 28

Rep: Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178
Quote:
Originally Posted by aghabriel View Post
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
 
Old 04-06-2012, 08:28 AM   #23
rahulu123
LQ Newbie
 
Registered: Mar 2012
Posts: 3

Rep: Reputation: Disabled
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
 
Old 04-08-2012, 11:22 AM   #24
doru
Member
 
Registered: Sep 2008
Distribution: Ubuntu 8.04 LTS Server
Posts: 85

Rep: Reputation: 16
Quote:
Originally Posted by rahulu123 View Post
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:
Code:
ls | tee -a file
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 11:48 AM.
 
Old 04-10-2012, 09:00 AM   #25
rahulu123
LQ Newbie
 
Registered: Mar 2012
Posts: 3

Rep: Reputation: Disabled
Quote:

You may want to try:
Code:

Code:
ls | tee -a file
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
 
Old 07-02-2012, 07:12 PM   #26
BeachHead
LQ Newbie
 
Registered: May 2012
Location: Germany
Distribution: Arch, AOSP
Posts: 24

Rep: Reputation: 2
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 07:22 PM.
 
  


Reply

Tags
pipe, redirect, stderr, stdout, tee


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
How to redirect output to a file? mus1402 Linux - Newbie 2 02-05-2006 10:42 AM
redirect screen output to file timbuck Linux - Software 5 12-09-2005 07:57 PM
how to redirect the soundcard output to a file? jr0 Linux - General 2 10-31-2005 07:29 AM
Is there a way in Linux/Unix bash to turn off output or redirect to a file jimwelc Linux - Newbie 6 01-06-2005 04:56 AM
output from cpio won't redirect to file rawii Programming 5 01-27-2004 02:49 PM


All times are GMT -5. The time now is 03: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