O'Reilly logo

Learning the UNIX Operating System, Fourth Edition by Jerry Peek, John Strang, Grace Todino

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

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), 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.

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required