home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

Learning the Unix Operating System

Learning the Unix Operating SystemSearch this book
Previous: 3.1 The UNIX Filesystem Chapter 3
Your UNIX Account
Next: 3.3 Protecting and Sharing Files
 

3.2 Looking Inside Files

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 .

3.2.1 cat

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:

cat file(s)

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 /etc/passwd


root:x&k8KP30f;(:0:0:Root:/:
daemon:*:1:1:Admin:/:
	.
	.
	.
%

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] .

3.2.2 more

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 file(s)

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:

% 

more ch03


A file is the unit of storage in UNIX as in many other systems.
A file can be anything: a program,
	.
	.
	.
--More--(47%)

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.

Table 3.1: Useful more Commands
Command Description
[SPACE] Display next page.
[RETURN] Display next line.
n f Move forward n pages.
b Move backward one page.
n b Move backward n pages.
/ word Search forward for word .
? word Search backward for word .
v Start the vi editor at this point.
[CTRL-L] Redisplay current page.
h Help.
:n Go to next file on command line.
:p Go back to previous file on command line.
q Quit more (before end of file).

3.2.3 pg

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:

pg filename(s)

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 ( : ) prompt. Press [RETURN] to view the next page or enter "q" to quit. Enter "h" for a list of pg commands.


Previous: 3.1 The UNIX Filesystem Learning the Unix Operating System Next: 3.3 Protecting and Sharing Files
3.1 The UNIX Filesystem Book Index 3.3 Protecting and Sharing Files

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System










??????????????@Mail.ru