Redirecting STDERR to STDOUT

If you want to use a pager program such as 'more' to scroll through large amounts of output from a program you can use a command such as:

ls -al | more

Here the output from 'ls -al' is piped to the 'more program', but this only works for the STDOUT output stream, any errors will still be printed directly to the terminal.

To catch any error messages that output using STDERR you will need to using a command like the one below:

ls -al 2>&1 | more

This example will pipe both STDOUT and STDERR to the 'more' program, as STDERR is redirected to the STDOUT output stream.

Last updated: 07/06/2005