Figure 6.3: Redirecting output

6.5 Controlling Input and Output

Throughout your experiences with Linux, you will most likely find that manipulating application input and output can be a very powerful thing to do. This section describes some of the things that controlling input and output can do for you.

6.5.1 stdin, stdout, Pipelines, and Redirection

Every process has at least three connections to the outside world. The standard input is one source of the process’s data; the standard output is one place the process sends data; and the standard error is a place the process can send error messages. (These are often abbreviated stdin, stdout, and stderr.)

The words “source” and “place” are intentionally vague. These standard input and output locations can be changed by the user; they could be the screen, the keyboard, a file, even a network connection. You can specify which locations to use.

When you run a program from the shell, usually standard input comes from your keyboard, and standard output and error both go to your screen. However, you can ask the shell to change these defaults.

For example, the echo command sends it output to standard output, normally the screen. But you can send it to a file instead with the output redirection operator, >. For example, to put the word “Hello” in the file myfile, use this command:

echo Hello > myfile