Skip to content. | Skip to navigation

Navigation

You are here: Home / Support / Guides / Scripting / Bash / Redirecting stdout/stderr / Basics

Personal tools

Redirecting stdout/stderr

Redirecting stdout and stderr to a file and have stdout and stderr available to redirect as normal.

Basics

Redirecting stdout and stderr can hardly be the topic of several webpages, surely?

cmd args > file 2>&1

So what's the problem?

The problem is that we really want to see the command's output as well as redirect it to a file. In fact, what we really want is to be able to redirect stdout and stderr how we like and still have all the output redirected to a file. Suddenly, that's not so easy.

There are a few solutions to the problem of redirecting stdout and stderr to a file that don't quite work.

The underlying problem we're facing is that, taking just stdout for a moment to simplify the problem, we've only got the one stdout stream coming from our program but we want two: one to continue going to stdout and the other to be redirected into a file. There are no file descriptor IO twiddles that can take a single IO stream and send it to two different places at once in the shell.

Document Actions