|Previous||Table of Contents||Next|
The external pg command is used to examine a file one screen at a time. It functions as an enhanced cat command or a stripped down view command, providing functionality somewhere in between. The pg paginator allows you to:
Following is the general format of the pg command.
pg [ - ] [ -cefnrs ] [ -n ] [ -p prompt ] [ +line ] [ +/pattern/ ] \ file_list
The following list describes the options and their arguments used to control how pg functions.
|-||Forces pg to read from the standard input.|
|-c||Home the cursor and clear the screen before displaying each screen. Each page is displayed on a clear screen instead of scrolling the lines. The TERM variable must be defined. The TERMinal type must have clear screen capabilities defined in the TERMCAP or TERMINFO database.|
|-e||Don't prompt for a response at the end of each file. Normally pg prompts you at the end-of-file.|
|-f||Inhibits line splitting. If a line is longer than the screen width, pg normally splits the line. For instance, if the line has many escape sequences to control terminal attributes, pg will split the line and it will appear incorrect. The -f option is useful when characters that don't appear on the display are embedded in the file.|
|-n||Does not require a new-line character to process a command. Single-letter commands are interpreted and processed immediately.|
|-r||Restrict shell escape from pg. An error message is displayed if an attempt is made to escape to the shell.|
|-s||Turns on standout mode causing pg to display its prompts and messages in standout mode. Usually, this is reverse video. The TERMCAP or TERMINFO entry for the specified TERMinal defines what standout mode is on your terminal.|
|-n||Specifies the number of lines pg uses for the screen window. If the terminal is defined to have a 24-line screen, the window is set to 23 lines.|
|-p prompt||Changes the prompt displayed by pg to be prompt. Normally, a colon (:) is displayed. If %d is placed in the prompt string, the current page number is substituted.|
|+line||Begin displaying the file at line number line.|
|+/pattern/||Begin displaying the file at the first occurrence of pattern. Pattern may be a string or a regular expression.|
The following describes the argument that may be passed to the pg command.
|file_list||One or more files pg reads and displays on your terminal screen. pg prompts you between each file unless the -e option is used.|
After each screen is displayed pg prompts you for a response. There are three basic types of responses:
The pg command needs to know the attributes for your terminal. It searches the TERMCAP or TERMINFO database for the terminal defined by the TERM variable. If TERM is not set, pg assumes you are on a dumb terminal.
At the end of each screen pg prompts for a response. To continue you must enter one of the following commands at the prompt. The commands are separated into four categories:
These commands let you move around the current file (line-by-line motion only) and peruse the data. An address may be placed before these commands except for the Redisplay (. or Ctrl-L) and Last Screen ($) commands.
The address affects pages or lines depending on the command. Using these commands you can move to an absolute address or a relative address. An absolute address is measured from the beginning of the file. A relative address is measured from your current position within the file.
To move to an absolute address you precede the command with an unsigned number. For example, if you want to go to line 25 of the file you type 25l. To move to a relative address you precede the command with a signed number. For instance, +25l would move you forward 25 lines. To move backward you use -25l. The default address is a relative movement of +1 for each command. In the following descriptions adr refers to an address, the brackets () signify that the address is optional.
|[adr]Return||Display the page specified by address adr. If you use an unsigned number like 3, pg goes to page three. If you use +3, pg moves forward three pages. And -3 causes pg to move backward three pages. If you do not provide adr, +1 is assumed and the next page is displayed.|
|[adr]l||Scroll number of lines specified by address adr. If a number like 15 is used pg moves to line 15. If a +15 is is used pg moves forward 15 lines. And if -15 is used pg moves back 15 lines.|
|[adr]d||Scroll half of the screen length. A positive number means to scroll|
|[adr]Ctrl-D||forward. A negative number means scroll backward.|
The following two perusal commands do not accept addresses:
|. (period)||Redisplay the current screen. Use this command after using the h|
|Ctrl-L||command or if line noise has garbled your screen (if connected via a modem).|
|$||Go to the last screen of the current file and display it.|
The search commands provide a means of skipping forward or backward to an occurrence of a known text pattern. The pattern may be a simple string of text or a regular expression. Regular expressions are generalized patterns that match multiple sets of text. The regular expressions used by pg are the same as defined in Module 39, which discusses the ed command.
A pattern must end with a Return, even if the -n option is used. If the pattern being searched for is not found, the next page is displayed. The pattern is designated by the pat string in the following commands. The following commands are used to perform searches:
|[i]/pat/[tmb]||Search forward for the ith occurrence of the pattern pat. If you do not specify a number for i, 1 is assumed. The search starts with the next screen of data. Normally, the line containing the pattern is positioned at the top of the new screen. See Line Positioning in the following section for details on using tmb.|
|[i]^pat^[tmb]||Search backward for the ith occurrence of the pattern pat. Again, 1 is|
|[i]?pat?[tmb]||assumed if you do not specify i. The search begins on the line above the current screen. Some terminals do not handle the question mark (?) properly; if your terminal is one of these, use the caret (^) notation.|
Line Positioning By specifying one of the t, m, or b line positioning letters you can have the line displayed in one of three positions:
|t||Display the line that the pattern was found on at the top of the screen.|
|m||Display the line that the pattern was found on in the middle of the screen.|
|b @ @T2 =||Display the line that the pattern was found on at the bottom of the screen.|
The last letter specified remains in effect until a new letter is used. The t letter remains in effect until you change it to m or b.
The environment commands are used to change the viewing environment of the pg command. You can skip forward or backward to different files or reset the window size by using the following commands:
|[i]n||Skip forward to the ith next file specified on the command line. If you do not specify i, 1 is assumed.|
|[i]p||Skip backward to the ith previous file specified on the command line. If you do not specify i, 1 is assumed.|
|[i]w||Set the window size to i. The next window will be displayed. If i is not given, the same window size is used and the next screen of data is displayed.|
The following commands are used to perform various functions while using pg.
|s filename||Save the input in a file named filename. The input could be a pipe; by using the s command you can save it to disk. Only the current file (input stream) is saved.|
|Displays a help screen. A summary of each pg command is given. To redraw the same screen of text type Ctrl-L or . (period). To display the next screen press Return.|
|!command||Escape to shell. The command is passed to the command interpreter defined by the SHELL variable. If SHELL is not set, the default shell is used. The default is usually /bin/sh.|
|If a QUIT or INTERRUPT signal is sent to pg while it is writing output, it stops sending output and displays the command prompt. The QUIT signal is generated by pressing Ctrl-\. The INTERRUPT signal is generated by pressing Ctrl-C or Del. If either of these signals are sent while pg is at the command prompt, pg terminates or begins displaying the next file if present. The display may become garbled if one of these signals is sent while text is being displayed.|
DIAGNOSTICS AND BUGS
If the terminal you are using does not handle tabs properly, the output may be formatted incorrectly.
If you are using pg as a filter with another command that changes your terminal I/O settings, the settings may not be reset properly.
Refer to the cat, grep, head, sed, and tail commands described in modules 13, 60, 63, 117, and 131, respectively.
The pg command is a filter that reads the standard input and writes to the standard output. It can also read from a list of files.
If the standard output is redirected to a file or pipe (it no longer is the terminal), pg performs much like the cat command. If there is more than one file, pg places a header at the top of each file.
The pg command provides a powerful and flexible way of viewing files larger than a screen in length. It can be used in place of the cat or view command. It provides the ability to search for strings and skip lines forward and backward. It can also move between multiple files.
In this activity you use the pg command to find your login entry in the /etc/passwd file. Begin at the shell prompt.
|Previous||Table of Contents||Next|