Chapter 6. Redirecting I/O

Many Unix programs read input (such as a file) and write output in a standard way that lets them work with each other. 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 Mac 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 lines, then 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.

Standard Input and Standard Output

What happens if you don’t give a filename argument on a command line? Most programs take their input from your keyboard instead (after you press ...

Get Learning Unix for Mac OS X Tiger now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.