Understand Input/Output StreamsTo take advantage of the information in this chapter, you need to understand that there are three input/output streams for a Linux shell: standard input, standard output, and standard error. Each of these streams has a file descriptor (or numeric identifier), a common abbreviation, and a usual default. For instance, when you're typing on your keyboard, you're sending input to standard input, abbreviated as stdin and identified as 0. When your computer presents output on the terminal, that's standard output, abbreviated as stdout and identified as 1. Finally, if your machine needs to let you know about an error and displays that error on the terminal, that's standard error, abbreviated as stderr and identified as 2. Let's look at these three streams using a common command, ls. When you enter ls on your keyboard, that's using stdin. After typing ls and pressing Enter, the list of files and folders in a directory appears as stdout. If you try to run ls against a folder that doesn't exist, the error message that appears on your terminal is courtesy of stderr. Table 4.1 can help you keep these three streams straight.
In this chapter, we're going to learn how to redirect input and output. Instead of having output appear on the terminal, for instance, you can redirect it to another program. Or instead of acquiring input from your typing, a program can get it from a file. After you understand the tricks you can play with stdin and stdout, there are many powerful things you can do. |