LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 06-15-2006, 05:30 PM   #1
mathfeel
Member
 
Registered: Feb 2002
Distribution: Gentoo
Posts: 95

Rep: Reputation: 15
Question how to append stderr?


I know that > and >& writes stdout and stdout+stderr to a file, respetively.
I also know that >> appends stdout to a file.
Is there a similar thing for appending stdout+stderr? Thanks
 
Old 06-15-2006, 06:21 PM   #2
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
The only way I can think of:
Code:
(insert_command_here 2>&1) >> some_file
The 2>&1 will redirect stderr to stdout, and >> will append stdout (which is also stderr because of the previous redirection) to some_file.
 
Old 06-16-2006, 12:41 AM   #3
mathfeel
Member
 
Registered: Feb 2002
Distribution: Gentoo
Posts: 95

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by zhangmaike
The only way I can think of:
Code:
(insert_command_here 2>&1) >> some_file
The 2>&1 will redirect stderr to stdout, and >> will append stdout (which is also stderr because of the previous redirection) to some_file.
I saw lots of sample code with 1 and 2, never understood what they mean. So 1 means stdout, 2 means stderr?
 
Old 06-16-2006, 01:05 AM   #4
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
Output redirection involves the manipulation of file descriptors, which are themselves numbers.

Redirecting output from stdout/stderr to stderr/stdout/a file merely changes which file descriptor is being used.

stdin is file descriptor 0
stdout is file descriptor 1
stderr is file descriptor 2

Quote:
So 1 means stdout, 2 means stderr?
Yes.

If you're interested, there is a huge section on redirection in the bash manpage which covers not only this sort of redirection, but also redirection to/from hosts through tcp or udp ports.

Last edited by zhangmaike; 06-16-2006 at 01:13 AM.
 
  


Reply



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
syslogd and stderr slzckboy Linux - General 4 01-16-2006 04:45 PM
stderr messages bokini Linux - General 1 11-29-2005 07:30 AM
stderr redirection evilop Linux - Newbie 3 09-21-2004 04:27 PM
redirecting stderr nodger Programming 2 03-11-2004 10:58 AM
stderr is not a tty where are you? davidschob Slackware 6 10-31-2003 10:38 AM

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

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