Output Redirection Operator Definition

The output redirection operator is a rightward pointing angular bracket (>) that is used in shells to redirect standard output to a file, where it is written and saved, or to a device (such as a printer, where it is printed).

A shell is a program that provides the traditional, text-only user interface for Linux and other Unix-like operating systems. Its primary function is to read commands that are typed into a console (i.e., an all-text display mode) or into a terminal window (i.e., an all-text window) in a GUI (graphical user interface) and then execute (i.e., run) them.

Standard output, sometimes abbreviated stdout, refers to the destination of the output from command line programs (i.e., programs that operate from the command line or from a shell) in Unix-like operating systems. It is by default the display screen. That is, command line programs automatically send their output to the screen unless instructed to do otherwise. Standard output can be redirected from the screen to a file where it is written and saved, to a printer where it is printed, or to another program where it is used as an input.

For example, the output of the cat command, which is commonly used to read files, could be redirected when it reads a file named file1 from the display screen, where it would otherwise appear by default, to a file named file2 with the following:

cat file1 > file2

If file2 already exists, the output redirection operator will overwrite its contents. If it does not yet exist, the output redirection operator will create it.

Likewise, a list of filesystem objects (i.e., files, directories and links) in the current directory can be written to a file named, for example, file3 with the ls command followed by the the output redirection operator:

ls > file3

There are other types of operators that are also used with redirection. Among them is the append operator, which is similar to the output redirection operator except that it is represented by two successive rightward pointing angle brackets (>>) and adds text from a file or other source to the end of file, if a file with the target name already exists, rather than overwriting the file.

The input redirection operator, which is represented by a leftward-pointing angular bracket (<), redirects standard input from its default (which is text typed in at the keyboard) so that the data comes instead from a file. The standard error redirection operator, which consists of a rightward facing angular bracket preceded directly (i.e., without any intervening space) by the numeral 2 (2>), is used to redirect the standard error (i.e., the destination of error messages from command line programs).

The pipe, which is represented by the vertical bar character (|), can also be considered a type of output redirection operator. However, it differs from the rightward pointing angle bracket operator in that it only redirects standard output to another program and not to a file or device.

Created March 4, 2007.
Copyright © 2007 The Linux Information Project. All Rights Reserved.