Redirect error to standard output

Assume we are executing a program and want to read the error. Usually the error output is just running up fastly and then left you at the last error only. So, we need to display it per page. But How. Because Linux send the error output in different ‘channel’ then normal output (called standard output).


The error come out from this program execution will run to the end rather than displayed correctly per page.

$ ./ | more

What you do above is actually display the standard output. So you cannot catch the error, even they still printed in screen.

Redirect to file

Yes, instead of display directly in screen, you can save (read: redirect) the error output to screen. This is what normally I do. Because I can read it later.

$ ./ 2> error.$(date +%Y%m%d-%H%M).log
$ more error.20160101-0920.log  # the filename is example only

But, for some reason, we need to display it directly. What we can do is something like this

$ ./ 2>&1 | more

The command above is to send the error output to standard output (2>&1) and then pipe it to more (you can use less for more interactive navigation). Using more (or less) is my recommended way, due to the output can be very-very long.



Silahkan berkomentar ...

Isikan data di bawah atau klik salah satu ikon untuk log in:


You are commenting using your account. Logout /  Ubah )

Foto Google+

You are commenting using your Google+ account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )


Connecting to %s