Many Unix programs read input (such as from a file) and write output in a standard way that lets them work with one another. This exchange of information is commonly known in Unix circles as I/O (pronounced “eye-oh,” which is short for input/output). In this chapter, we discuss some of these tools and learn how to connect programs and files in new and powerful ways.
This chapter generally doesn’t apply to programs, such as the vi editor, that take control of your entire Terminal window. (less does work in this way, however.) It also doesn’t apply to graphical programs that open their own windows on your screen, such as iTunes or Safari. On the other hand, the vast majority of Unix commands that you use on the command line are line-oriented, and they’re exactly why I/O redirection is included in OS X’s Unix.
The difference between “screen-oriented” and “line-oriented” is a bit tricky to figure out when you’re just starting. Think of it this way: if you can use arrow keys to move up and down, it’s a screen-oriented program. The vi editor is the classic example of a screen-oriented program. If the input or output is all shown line by line, as in the ls command’s output, then it’s a line-oriented command. Almost all Unix commands are line-oriented, as you’ll see in this chapter.
What happens if you don’t give a filename argument in a command line? Most programs take their input from your keyboard instead (after you press ...