Skip to content


Linux, terminal redirect output

Linux uses two different kinds of output. STDOUT and STDERR. As the name suggests, normal output usually is written to stdout, while errors are sent to stderr. However, it is the responsibility of the program(e.g. the programmer) to do so, therefore it can be that error messages are also sent to stdout.

When using the terminal, both stdout and stderr are by default shown. stdout is associated with 1, stderr with 2. For the sake of completeness, the number 0 stands for stdin, a way of inputting data.

To redirect the normal output (stdin) to a file use:

myprogram 1> /path/to/some/file

In this case, the output file is always replaced. To append to an already existing file use

myprogram 1>> /path/to/some/file

To redirect stderr to a file use:
myprogram 2> /path/to/some/file

In this case, the output file is always replaced. To append to an already existing file use

myprogram 2>> /path/to/some/file

To redirect both stdout and stderr to the same file, use:

myprogram > /path/to/some/file 2>&1

In this case, the output file is always replaced. To append to an already existing file use

myprogram >> /path/to/some/file 2>&1



Posted in ITechnische Post.

Tagged with , , .