There is absolutely no difference between reading data from a file and reading data from a terminal.  Likewise, if a program's output consists entirely of alphanumeric characters and punctuation, there is no difference between writing to a file, writing to a terminal, and writing to the input of another program (as in a pipe).
The standard I/O facility provides some simple defaults for managing Input/Output. There are three default I/O streams: standard input, standard output, and standard error. By convention, standard output (abbreviated stdout ) consists of all "normal" output from your program, while standard error ( stderr ) consists of error messages. It is often a convenience to be able to handle error messages and standard output separately. If you don't do anything special, programs will read standard input from your keyboard, and they will send standard output and standard error to your terminal's display.
Standard input (
) normally comes from your keyboard.
Many programs ignore
; you name files directly
on their command line - for instance, the command
cat file1 file2
never reads its standard input; it reads the files directly.
But, without filenames on the command line, UNIX commands that need input
will usually read
Standard input normally comes from your keyboard, but the shell can
from a file.
This is handy for UNIX commands that can't open files directly - for instance,
To mail a file to
The real virtue of standard I/O is that it allows you to redirect input or output away from your terminal to a file. As we said, UNIX is . Because terminals and other I/O devices are treated as files, a program doesn't care or even know  if it is sending its output to a terminal or to a file. For example, if you want to run the command cat file1 file2 , but you want to place the output in file3 rather than sending it to your terminal, give the command:
This is called
standard output to
you give this command and look at
you will find the contents of
, followed by
-exactly what you would have seen on your screen if you
One of the best-known forms of redirection in UNIX is the
The shell's vertical bar (
The pipe says "connect the standard output of the process at the left
Be aware that:
Of course, programs aren't restricted to standard I/O. They can open other files, define their own special-purpose pipes, and write directly to the terminal. But standard I/O is the glue that allows you to make big programs out of smaller ones, and is therefore a crucial part of the operating system. Most UNIX utilities read their data from standard input and write their output to standard output, allowing you to combine them easily. A program that creates its own special-purpose pipe may be very useful, but it cannot be used in combination with standard utilities.
Some UNIX systems, and utilities such as , support special filenames like /dev/stdin , /dev/stdout , and /dev/stderr . You can use these just as you'd use other files. For instance, to have any ordinary command read from the file afile , then standard input (from the keyboard, for example), then the file bfile :