Reading a File
Okay, by now you are ready to do more than just find files and check out or modify their permissions. The next step, of course, is to actually look at the contents of the files you've discovered in the various directories provided you have permission.
There are several ways to read files in the UNIX system besides using a word processor such as vi or emacs (we won't cover those here because they require a tutorial all in themselves, but there are plenty of good books out there on the processors.)
The "cat" Utility
An example usage of each is shown below:
Some UNIX systems also include the "tac" utility which behaves exactly like "cat" except that it displays the file in reverse order, from bottom to top.
As with most utilities, the "cat" utility has several useful options that are explored in the table below:
Give it a try, Go ahead and "cat" a file.
The "more" Utility
As usual, the more utility comes with several options and arguments and follows the generic form of
more [options] [+linenumber] [+/pattern] filelist
The options are explained in the following table
It is also common to see more used at the end of a pipeline when the utilities involved may produce output greater than the length of a screen. For example, to restrict the listing of a full directory, you might use the more utility in a pipeling such as in the following example:
ls -l | more
By the way, Some UNIX systems also include the "less" utility that behaves exactly like "more" except that it displays the file in reverse order, from bottom to top.
Give it a try, go ahead and use "more" to read a file.
The "pg" Utility
The "head" Utility
head -lines filelist
The "tail" Utility
tail -lines filelist
Check out the following example