Standard I/O and Default File Descriptors
Standard I/O is a capability of the shell, used with all text-based Linux utilities to control and direct program input, output, and error information. When a program is launched, it is automatically provided with three file descriptors. File descriptors are regularly used in programming and serve as a “handle” of sorts to another file. We have mentioned these already in our discussion of text streams and “piping” together programs on the command line. Standard I/O creates the following file descriptors:
- Standard input (abbreviated stdin)
This file descriptor is a text input stream. By default it is attached to your keyboard. When you type characters into an interactive text program, you are feeding them to standard input. As you’ve seen, some programs take one or more filenames as command-line arguments and ignore standard input. Standard input is also known as file descriptor 0.
- Standard output (abbreviated stdout)
This file descriptor is a text output stream for normal program output. By default it is attached to your terminal (or terminal window). Output generated by commands is written to standard output for display. Standard output is also known as file descriptor 1.
- Standard error (abbreviated stderr)
This file descriptor is also a text output stream, but it is used exclusively for errors or other information unrelated to the successful results of your command. By default, standard error is attached to your terminal just like standard output. ...