LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 02:17 PM   #16
Fitch
LQ Newbie
 
Registered: Feb 2011
Location: Edinburgh
Distribution: Ubuntu 22.04
Posts: 29

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

Rep: Reputation: 58
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.
Old 04-03-2011, 02:02 PM   #18
Fitch
LQ Newbie
 
Registered: Feb 2011
Location: Edinburgh
Distribution: Ubuntu 22.04
Posts: 29

Rep: Reputation: 1
Got it! Thanks Dave
 
Old 04-21-2011, 04: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, 01: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, 04: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 04:37 AM.
 
Old 03-23-2012, 06:04 AM   #22
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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, 07: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, 10:22 AM   #24
doru
Member
 
Registered: Sep 2008
Distribution: Ubuntu 8.04 LTS Server
Posts: 138

Rep: Reputation: 19
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 10:48 AM.
 
Old 04-10-2012, 08: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, 06: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 06:22 PM.
 
Old 10-12-2017, 02:27 PM   #27
Mr. Macintosh
Member
 
Registered: Sep 2015
Distribution: Debian
Posts: 297

Rep: Reputation: 60
Huh?

How does ls -i help in this situation? Last time I checked, the ls command lists the contents of a directory.
 
Old 10-20-2017, 03:45 AM   #28
doru
Member
 
Registered: Sep 2008
Distribution: Ubuntu 8.04 LTS Server
Posts: 138

Rep: Reputation: 19
Quote:
Originally Posted by Mr. Macintosh View Post
How does ls -i help in this situation? Last time I checked, the ls command lists the contents of a directory.
No such thing here.
 
  


Reply

Tags
pipe, redirect, stderr, stdout, tee



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 09:42 AM
redirect screen output to file timbuck Linux - Software 5 12-09-2005 06:57 PM
how to redirect the soundcard output to a file? jr0 Linux - General 2 10-31-2005 06: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 03:56 AM
output from cpio won't redirect to file rawii Programming 5 01-27-2004 01:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:51 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration