LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-12-2004, 12:17 PM   #1
granny
Member
 
Registered: Nov 2002
Distribution: RH
Posts: 141

Rep: Reputation: 15
redirecting output to multiple outputs


I want to redirect output to multiple places, how can this be done. Something simple as...

ls /etc redirected to both a file and monitor. I know how to redirect to a file and understand std output is monitor, but how do I do both in 1 command?

ls /etc > file and then???
 
Old 02-12-2004, 01:01 PM   #2
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
Code:
ls /etc/ 2>&1 | tee file
Hope this help you
 
Old 02-12-2004, 01:04 PM   #3
granny
Member
 
Registered: Nov 2002
Distribution: RH
Posts: 141

Original Poster
Rep: Reputation: 15
sweet, thanks oliv, worked perfectly. What did the 2>&1 do though
 
Old 02-12-2004, 01:11 PM   #4
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
If my memory is good: 2>&1 is used to duplicate stderr to stdout
 
Old 02-12-2004, 02:56 PM   #5
granny
Member
 
Registered: Nov 2002
Distribution: RH
Posts: 141

Original Poster
Rep: Reputation: 15
that's what I though, but ls /etc isn't an err so why does it work. Wouldn't it just produce stnd out? Either way thanks Oliv!
 
Old 02-13-2004, 07:27 AM   #6
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
It works because stdout remains stdout... You just add messages from stderr to stdout.
It's just a precaution if you process commands which can cause errors
 
Old 02-13-2004, 08:18 AM   #7
hiteshmaisheri
Member
 
Registered: Nov 2003
Location: Kerala, India
Distribution: Red Hat, Knoppix, Mandrake, FreeBSD
Posts: 231

Rep: Reputation: 30
the 2>&1 means that both stdout and sterr to the pipe and then to the tee command and to the file
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirecting mplayer output driptray Linux - Software 1 10-12-2004 08:42 AM
redirecting output in Bourne shell trutnev Linux - Software 2 04-22-2004 04:55 AM
redirecting xmms output durden2.0 Linux - Software 0 03-06-2004 08:29 PM
RedHat 8.0 multiple sound outputs heathimself Linux - Distributions 2 12-06-2003 03:39 AM
multiple outputs from xmms walrus_55 Linux - Software 0 10-20-2003 01:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

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