Redirecting / Merging stdout and stderr streams

To merge the standard out and standard error streams from a program, use 2>&1.

Example: umount /adsf/asdf 2>&1 will output the errors into standard out instead of standard error as usual.

Note that:

  • 2 is the file descriptor for stderr.
  • 1 is the file descriptor for stdout.
  • & accepts a file descriptor which can then be treated as a file.

Thus, 2>&1 in turns ‘writes data’ from stderr into stdout.

Leave a Reply

Your email address will not be published.