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 |
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
02-12-2004, 12:17 PM
|
#1
|
Member
Registered: Nov 2002
Distribution: RH
Posts: 141
Rep:
|
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???
|
|
|
02-12-2004, 01:01 PM
|
#2
|
Senior Member
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014
Rep:
|
Code:
ls /etc/ 2>&1 | tee file
Hope this help you
|
|
|
02-12-2004, 01:04 PM
|
#3
|
Member
Registered: Nov 2002
Distribution: RH
Posts: 141
Original Poster
Rep:
|
sweet, thanks oliv, worked perfectly. What did the 2>&1 do though
|
|
|
02-12-2004, 01:11 PM
|
#4
|
Senior Member
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014
Rep:
|
If my memory is good: 2>&1 is used to duplicate stderr to stdout
|
|
|
02-12-2004, 02:56 PM
|
#5
|
Member
Registered: Nov 2002
Distribution: RH
Posts: 141
Original Poster
Rep:
|
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!
|
|
|
02-13-2004, 07:27 AM
|
#6
|
Senior Member
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014
Rep:
|
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
|
|
|
02-13-2004, 08:18 AM
|
#7
|
Member
Registered: Nov 2003
Location: Kerala, India
Distribution: Red Hat, Knoppix, Mandrake, FreeBSD
Posts: 231
Rep:
|
the 2>&1 means that both stdout and sterr to the pipe and then to the tee command and to the file
|
|
|
All times are GMT -5. The time now is 01:10 PM.
|
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
|
|