Syntax

Parameters

Parameter | Details |

——— | —–– | internal file descriptor | An integer. |

direction | One of \\>, \\< or <> | external file descriptor or path | & followed by an integer for file descriptor or a path. |

Remarks

UNIX console programs have an input file and two output files (input and output streams, as well as devices, are treated as files by the OS.) These are typically the keyboard and screen, respectively, but any or all of them can be redirected to come from — or go to — a file or other program.

STDIN is standard input, and is how the program receives interactive input. STDIN is usually assigned file descriptor 0.

STDOUT is standard output. Whatever is emitted on STDOUT is considered the “result” of the program. STDOUT is usually assigned file descriptor 1.

STDERR is where error messages are displayed. Typically, when running a program from the console, STDERR is output on the screen and is indistinguishable from STDOUT. STDERR is usually assigned file descriptor 2.

The order of redirection is important

command > file 2>&1

Redirects both (STDOUT and STDERR) to the file.