By now, you're probably tired of looking at files from the outside. It's kind of like going to a bookstore and looking at the covers, but never getting to read a word. Let's look at three programs for reading files: cat , more , and pg .
Most first-time users of UNIX think that cat is a strange name for a program. As we'll see later, cat , which is short for "concatenate," puts files together (concatenates them) to make a bigger file. It can also display files on your screen.
To display files on the standard output (your screen; see Chapter 5, Redirecting I/O ), use:
For example, let's display the contents of the file /etc/passwd . This system file describes users' accounts. (Your system may have a more complete list somewhere else.)
cat works best for short files containing one screenful or less. If you cat a file that is too long, it may roll up the screen faster than you can read it. You cannot go back to view the previous screens when you use cat (unless you're using an xterm window with a scrollbar, that is).
If you enter cat without a filename, get out by pressing [RETURN] followed by a single [CTRL-D] .
If you want to "read" a long file on the screen, your system may have the more command to display one screen or "page" of text at a time. A standard terminal screen can usually display 24 lines of text; a window can display almost any number of lines. The syntax is:
more lets you move forward in the files by any number of pages or lines. Most versions let you move backward, too. You can also move back and forth between two or more files specified on the command line. When you invoke more , the first "page" of the file appears on the screen. A prompt appears at the bottom of the screen, as in the following example:
The prompt says that you are 47% of your way through the file. The cursor sits to the right of this prompt as a signal for you to enter a more command to tell more what to do.
You can press "h" (for "help") at the more prompt to display the more commands available on your system. Table 3.1 lists some of the simpler (but quite useful) ones.
The more command isn't available on some UNIX systems. Most of those systems have the pg command instead. It works like more but has different features. For example, pg lets you move to specific lines.
The syntax is:
If your system has pg
, try it on a file that has
more lines than your screen.
Your screen displays the first page of the file.
The last line is a colon (