Before we cover viewing files, let's talk about redirection for a minute because I use some redirection in the upcoming section. I cover redirection under shell programming, but for now, I want to give you just a quick introduction to redirection so that we can more effectively cover some of the commands in this chapter. UNIX is set up such that commands usually take their input from the keyboard, often called standard input , and usually send their output to the screen, often called standard output . Commands also send error information to the screen. It is not always desirable for input to come from standard input and output and errors to go to standard output. You are given a lot of control to override these defaults. This is called redirection. Table 22-1 shows many common forms of redirection. As shown in the table, to redirect the output of a command from standard output to a file, you would use ">". This works almost all of the time. If you have an environment variable called noclobber set, then redirecting to an existing file does not work (we'll cover environment variables shortly). The noclobber does not permit redirection to write over an existing file. If you try to write over an existing file, such as /tmp/processes below, you receive a message that the file exists: # ps -ef > /tmp/processes /tmp/processes: File exists You can, however, use a "!" with redirection to force a file to be overwritten. Using ">!" forces a file to be overwritten, and ">>!" will force the output to be appended to the end of an existing file. Examples of these are shown in Table 22-1. Table 22-1. Commonly Used Redirection Forms
Using the symbols shown in Table 22-1, you can redirect from standard input and standard output . For instance, rather than display the out put on the screen, you can send the output to file. We will use some of these redirection forms in upcoming examples. |