Linux append STDERR and STDOUT to file


In Linux we will append STDOUT by using “>” or “>>” .


$ ls > temp.txt

It will create a file temp.txt and writes output(STDOUT) to it. If temp.txt exits it will remove existing temp.txt and writes output to it.

$ ls >> temp.txt

It will append output(STDOUT) to existing temp.txt file without removing it.

$ ls >> temp.txt 2>&1

It will append output(both STDERR and STDOPT) to temp.txt

Understanding I/O streams numbers

The Unix / Linux standard I/O streams with numbers:

Handle Name Description
0 stdin Standard input
1 stdout Standard output
2 stderr Standard error

The following example will redirect program error message (STDERR only) to a file called error.log:

$ command 2> your_error.log



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s