CONTENTS |
Before we can get into any serious work with UNIX commands, we'll cover a few different ways to view files in this chapter. Many of the commands covered in this chapter for viewing files will be used in many chapters throughout the book.
Another topic important to many of the UNIX commands to be covered as well as viewing files is redirection. In this chapter, we'll see some commonly used redirection techniques and then some methonds of viewing files. In fact, the very first viewing command that is covered in this chapter uses redirection, so it's important that you understand the basics of redirection before proceeding further. Here's what we'll cover in this chapter:
Redirection
cat, more, pg, head, and tail commands for viewing files
Before we cover viewing files, let's talk about redirection for a minute because I use some redirection in the upcoming section. I cover redirection under shell programming, but for now, I want to give you just a quick introduction to redirection so that we can more effectively cover some of the commands in this chapter.
UNIX is set up such that commands usually take their input from the keyboard, often called standard input, and usually send their output to the screen, often called standard output. Commands also send error information to the screen. It is not always desirable for input to come from standard input and output and errors to go to standard output. You are given a lot of control to override these defaults. This is called redirection. Table 4-1 shows many common forms of redirection.
As shown in the table, to redirect the output of a command from standard output to a file, you would use ">". This works almost all of the time. If you have an environment variable called noclobber set, then redirecting to an existing file does not work (we'll cover environment variables shortly). The noclobber does not permit redirection to write over an existing file. If you try to write over an existing file, such as /tmp/processes below, you receive a message that the file exists:
# ps -ef > /tmp/processes /tmp/processes: File exists
You can, however, use a "!" with redirection to force a file to be overwritten. Using ">!" forces a file to be overwritten, and ">>!" will force the output to be appended to the end of an existing file. Examples of these are shown in Table 4-1.
Command or Assignment | Example | Description |
---|---|---|
< | wc-l<.loginStandard | input redirection: execute wc (word count) and list number of lines (-l) in.login |
> | ps -ef > /tmp/processes | Standard output redirection: execute ps and send outputto file/tmp/processes |
>> | ps -ef >> /tmp/processes | Append standard output: execute ps and append outputto theend offile /tmp/processes |
>! | ps -ef >! /tmp/processes | Append output redirection and override noclobber: write over /tmp/processes, even if it exists |
>>! | ps -ef >>! /tmp/processes | Append standard output and override noclobber: append to the end of /tmp/processes |
| (pipe) | ps wc -l | Run ps and use the result as input to wc |
0 -standard input | ||
1 -standard output | ||
2 -standard error | cat program 2> errors | cat the file program to standard output and redirect errors to the file errors |
cat program 2>> errors | cat the file program to standard output and append errors to the file errors | |
find / -name '*.c' -print > cprograms 2>errors | find all files on the system ending in.c and place the list of files in cprograms in the current working directory and send all errors (file descriptor 2) to the file errors in current working directory | |
find / -name '*.c' -print > cprograms 2>&1 | find all files on the system ending in.c, place the list of files in cprograms in the current working directory, and send all errors (file descriptor 2) to same place as file descriptor 1 (cprograms) |
Using the symbols shown in Table 4-1, you can redirect from standard input and standard output. For instance, rather than display the output on the screen, you can send the output to file. We will use some of these redirection forms in upcoming examples.
To begin with, let's look at a long file. In fact, let's look at a file so long that it will not fit on your screen if you were to print out the contents of the file to your screen.
The cat command (short for concatenate) does just this; it prints out the file to your screen. If, however, the file is long, then you will only see the end of the file on your screen. Remember the user denise from earlier in the book? She had a lot of files in her directory. Let's list the files in her directory and redirect the output to a file called listing with the following command:
$ ls -a /home/denise > listing
When we cat listing to the screen, we see only the end of the file, as shown in Figure 4-1. We know that this is the end of the file because I have issued cat with the -n option, which includes line numbers. The line numbers indicate that this is not the beginning of the file.
Seeing only the end of this file is not what we had in mind. Using pg (for page), we see one screen at time, as shown in Figure 4-2:
The more command produces the same output as pg, as shown in Figure 4-3:
This is more like it; now we can scroll on a screen-by-screen basis with both pg and more. However, sometimes you want to view only the beginning or end of a file. You can use the head command to view the beginning of a file and the tail command to view theendofa file. The following two examples of head and tail (see Figures 4-4 and 4-5) show viewing the first 20 lines of listing and the last 20 lines of listing, respectively:
The command you use depends on the information you wish to display. My personal preference, whether viewing the contents of a large file or a long listing of files, is to use more. I don't have a good reason for this, and all I can say is that we are creatures of habit and I have always used more. The following are command summaries for cat, pg, more, head, and tail. I included some of the most frequently used options associated with these commands. Because none of the commands are difficult to use, I suggest that you try each command and see whether one suits your needs better than the others.
Here are summaries of the cat, pg (not available on all UNIX variants,) more, head, and tail commands.
cat - Display, combine, append, copy, or create files.
|
pg - Display all or parts of a file.
|
more - Display all or parts of a file one screen at a time.
|
head - Provide only the first few lines of a file.
|
tail - Provide the last few lines of a file.
|
The following are the HP-UX manual pages for many of the commands used in the chapter. Commands often differ among UNIX variants, so you may find differences in the options or other areas for some commands; however, the following manual pages serve as an excellent reference.
cat - Concatenate files.
cat(1) cat(1) NAME cat - concatenate, copy, and print files SYNOPSIS cat [-benrstuv] file ... DESCRIPTION cat reads each file in sequence and writes it on the standard output. Thus: cat file prints file on the default standard output device; cat file1 file2 > file3 concatenates file1 and file2, and places the result in file3. If - is appears as a file argument, cat uses standard input. To combine standard input and other files, use a combination of - and file arguments. Options cat recognizes the following options: -b Omit line numbers from blank lines when -n option is specified. If this option is specified, the -n option is automatically selected. -e Print a $ character at the end of each line (prior to the new-line). If this option is specified, the -v option is automatically selected. -n Display output lines preceded by line numbers, numbered sequentially from 1. -r Replace multiple consecutive empty lines with one empty line, so that there is never more than one empty line between lines containing characters. -s Silent option. cat suppresses error messages about non existent files, identical input and output, and write errors. Normally, input and output files cannot have identical names unless the file is a special file. -t Print each tab character as ^I. If this option is specified, the -v option is automatically selected. -u Do not buffer output (handle character-by-character). Normally, output is buffered. -v Cause non-printing characters (with the exception of tabs, new-lines and form-feeds) to be printed visibly. Control characters are printed using the form ^X (Ctrl-X), and the DEL character (octal 0177) is printed as ^? (see ascii(5)). Single-byte control characters whose most significant bit is set, are printed using the form M-^x, where x is the character specified by the seven low order bits. All other non-printing characters are printed as M-x, where x is the character specified by the seven low order bits. This option is influenced by the LC_CTYPE environment variable and its corresponding code set. EXTERNAL INFLUENCES Environment Variables LANG provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the default value of "C" (see lang(5)) is used. If any of the internationalization variables contains an invalid setting, cat will behave as if all internationalization variables are set to "C". See environ(5). LC_ALL If set to a non-empty string value, overrides the values of all the other internationalization variables. LC_CTYPE determines the interpretation of text as single and/or multi-byte characters, the classification of characters as printable, and the characters matched by character class expressions in regular expressions. LC_MESSAGES determines the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. NLSPATH determines the location of message catalogues for the processing of LC_MESSAGES. International Code Set Support Single- and multi-byte character code sets are supported. RETURN VALUE Exit values are: 0 Successful completion. >0 Error condition occurred. EXAMPLES To create a zero-length file, use any of the following: cat /dev/null > file cp /dev/null file touch file The following prints ^I for all the occurrences of tab character in file1 cat -t file1 To suppress error messages about files that do not exist, use: cat -s file1 file2 file3 > file If file2 does not exist, the above command concatenates file1 and file3 without reporting the error on file2. The result is the same if -s option is not used, except that cat displays the error message. To view non-printable characters in file2, use: cat -v file2 WARNINGS Command formats such as cat file1 file2 > file1 overwrites the data in file1 before the concatenation begins, thus destroying the file. Therefore, be careful when using shell special characters. SEE ALSO cp(1), more(1), pg(1), pr(1), rmnl(1), ssp(1). STANDARDS CONFORMANCE cat: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
head - Show first few lines of a file.
head(1) head(1) NAME head - give first few lines SYNOPSIS head [-c|-l] [-n count] [file ...] Obsolescent: head [-count] [file ...] DESCRIPTION head prints on standard output the first count lines of each of the specified files, or of the standard input. If count is omitted it defaults to 10. If multiple files are specified, head outputs before each file a line of this form: ==> file <== Options -c The quantity of output is measured in bytes. -count The number of units of output. This option is provided for backward compatibility (see -n below) and is mutually exclusive of all other options. -l The quantity of output is measured in lines; this is the default. -n count The number of lines (default) or bytes output. count is an unsigned decimal integer. If -n (or -count) is not given, the default quantity is 10. This option provides the same functionality as the -count option, but in a more standard way. Use of the -n option is recommended where portability between systems is important. EXTERNAL INFLUENCES Environment Variables LC_CTYPE determines the interpretation of text within file as single and/or multi-byte characters. LC_MESSAGES determines the language in which messages are displayed. If LC_CTYPE or LC_MESSAGES is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable. If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG. If any internationalization variable contains an invalid setting, head behaves as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single- and multi-byte character code sets are supported. SEE ALSO tail(1). STANDARDS CONFORMANCE head: SVID3, XPG4, POSIX.2
more - File-viewing filter.
more(1) more(1) NAME more, page - file perusal filter for crt viewing SYNOPSIS more [-n] [-cdefisuvz] [-n number] [-p command] [-t tagstring] [-x tabs] [-W option] [+linenumber] [+/pattern] [name ...] page [-n] [-cdefisuvz] [-n number] [-p command] [-t tagstring] [-x tabs] [-W option] [+linenumber] [+/pattern] [name ...] REMARKS: pg is preferred in some standards and has some added functionality, but does not support character highlighting (see pg(1)). DESCRIPTION more is a filter for examining continuous text, one screenful at a time, on a soft-copy terminal. It is quite similar to pg, and is retained primarily for backward compatibility. more normally pauses after each screenful, printing the filename at the bottom of the screen. To display one more line, press <Return>. To display another screenful press <Space>. Other possibilities are described later. more and page differ only slightly. more scrolls the screen upward as it prints the next page. page clears the screen and prints a new screenful of text when it prints a new page. Both provide one line of overlap between screenfuls. name can be a filename or -, specifying standard input. more processes file arguments in the order given. more supports the Basic Regular Expression syntax (see regexp(5)). more recognizes the following command line options: -n number Set the number of lines in the display window to number, a positive decimal integer. The default is one line less than the the number of lines displayed by the terminal; on a screen that displays 24 lines, the default is 23. The -n flag overrides any values obtained from the environment. -n Same as -n number except that the number of lines is set to n. -c Draw each page by beginning at the top of the screen, and erase each line just before drawing on it. This avoids scrolling the screen, making it easier to read while more is writing. This option is ignored if the terminal has no clear-to-end- of-line capability. -d Prompt user with the message Press space to continue, q to quit, h for help at the end of each screenful. This is useful if more is being used as a filter in some setting, such as a training class, where many users might be unsophisticated. -e Exit immediately after writing the last line of the last file in the argument list -f Count logical lines, rather than screen lines. That is, long lines are not folded. This option is recommended if nroff output is being piped through ul, since the latter can generate escape sequences. These escape sequences contain characters that would ordinarily occupy screen positions, but which do not print when sent to the terminal as part of an escape sequence. Thus more might assume lines are longer than they really are, and fold lines erroneously. -i Perform pattern matching in searches without regard to case. -s Squeeze multiple blank lines from the output, producing only one blank line. Especially helpful when viewing nroff output, this option maximizes the useful information present on the screen. -u Normally, more handles underlining and bold such as produced by nroff in a manner appropriate to the particular terminal: if the terminal supports underlining or has a highlighting (usually inverse-video) mode, more outputs appropriate escape sequences to enable underlining, else highlighting mode, for underlined information in the source file. If the terminal supports highlighting, more uses that mode information that should be printed in boldface type. The -u option suppresses this processing, as do the "ul" and "os" terminfo flags. -v Do not display nonprinting characters graphically; by default, all non-ASCII and control characters (except <Tab>, <Backspace>, and <Return>) are displayed visibly in the form ^X for <Ctrl-x>, or M-x for non-ASCII character x. -z Same as not specifying -v, with the exception of displaying <Backspace> as ^H, <Return> as ^M, and <Tab> as ^I. -p command Execute the more command initially in the command argument for each file examined. If the command is a positioning command, such as a line number or a regular expression search, sets the current position to represent the final results of the command, without writing any intermediate lines of the file. If the positioning command is unsuccessful, the first line in the file is the current position. -t tagstring Write the screenful of the file containing the tag named by the tagstring argument. The specified tag appears in the current position. If both -p and -t options are specified, more processes -t first; that is, the file containing the tagstring is selected by -t and then the command is executed. -x tabs Set the tabstops every tabs position. The default value for the tabs argument is 8. -W option Provides optional extensions to the more command. Currently, the following two options are supported: notite Prevents more from sending the terminal initialization string before displaying the file. This argument also prevents more from sending the terminal de-initialization string before exiting. tite Causes more to send the initialization and de-initialization strings. This is the default. +linenumber Start listing such that the current position is set to linenumber. +/pattern Start listing such that the current position is set to the line matching the regular expression pattern. The number of lines available per screen is determined by the -n option, if present or by examining values in the environment. The actual number of lines written is one less than this number, as the last line of the screen is used to write a user prompt and user input. The number of columns available per line is determined by examining values in the environment. more writes lines containing more characters than would fit into this number of columns by breaking the line into one more logical lines where each of these lines but the last contains the number of characters needed to fill the columns. The logical lines are written independently of each other; that is, commands affecting a single line affect them separately. While determining the number of lines and the number of columns, if the methods described above do not yield any number then more uses terminfo descriptor files (see term(4)). If this also fails then the number of lines is set to 24 and the number of columns to 80. When standard output is a terminal and -u is not specified, more treats backspace characters and carriage-return characters specially. - A character, followed first by a backspace character, then by an underscore (_), causes that character to be written as underlined text, if the terminal supports that. An underscore, followed first by a backspace character, then any character, also causes that character to be written as underlined text, if the terminal supports that. - A backspace character that appears between two identical printable characters causes the first of those two characters to be written as emboldened text, if the terminal type supports that, and the second to be discarded. Immediately subsequent occurrences of backspaces/character pairs for that same character is also discarded. - Other backspace character sequences is written directly to the terminal, which generally causes the character preceding the backspace character to be suppressed in the display. - A carriage-return character at the end of a line is ignored, rather than being written as a control character. If the standard output is not a terminal device, more always exits when it reaches end-of-file on the last file in its argument list. Otherwise, for all files but the last, more prompts, with an indication that it has reached the end of file, along with the name of the next file. For the last file specified, or for the standard input if no file is specified, more prompts, indicating end-fo-file, and accept additional commands. If the next command specifies forward scrolling, more will exit. If the -e option is specified, more will exit immediately after writing the last line of the last file. more uses the environment variable MORE to preset any flags desired. The MORE variable thus sets a string containing flags and arguments, preceded with hyphens and blank-character-separated as on the command line. Any command-line flags or arguments are processed after those in the MORE variable, as if the command line were as follows: more $MORE flags arguments For example, to view files using the -c mode of operation, the shell command sequence MORE='-c' ; export MORE or the csh command setenv MORE -c causes all invocations of more, including invocations by programs such as man and msgs, to use this mode. The command sequence that sets up the MORE environment variable is usually placed in the .profile or .cshrc file. In the following descriptions, the current position refers to two things: - the position of the current line on the screen - the line number (in the file) of the current line on the screen The line on the screen corresponding to the current position is the third line on the screen. If this is not possible (there are fewer than three lines to display or this is the first page of the file, or it is the last page of the file), then the current position is either the first or last line on the screen. Other sequences that can be typed when more pauses, and their effects, are as follows (i is an optional integer argument, defaulting to 1): i<Return> ij i<Ctrl-e> i<Space> Scroll forward i lines. The default i for <Space> is one screenful; for j and <Return> it is one line. The entire i lines are written, even if i is more than the screen size. At end-of-file, <Return> causes more to continue with the next file in the list, or exits if the current file is the last file in the list. id i<Ctrl-d> Scroll forward i lines, with a default of one half of the screen size. If i is specified, it becomes the new default for subsequent d and u commands. iu i<Ctrl-u> Scrolls backward i lines, with a default of one half of the screen size. If i is specified, it becomes the new default for subsequent d and u commands. ik i<Ctrl-y> Scrolls backward i lines, with a default of one line. The entire i lines are written, even if i is more than the screen size. iz Display i more lines and sets the new window (screenful) size to i . ig Go to line i in the file, with a default of 1 (beginning of file). Scroll or rewrite the screen so that the line is at the current position. If i is not specified, then more displays the first screenful in the file. iG Go to line i in the file, with a default of the end of the file. If i is not specified, scrolls or rewrites screen so that the last line in the file is at the bottom of the screen. If i is specified, scrolls or rewrites the screen so that the line is at the current position. is Skip forward i lines, with a default of 1, and write the next screenful beginning at that point. If i would cause the current position to be such that less than one screenful would be written, the last screenful in the file is written. if i<Ctrl-f> Move forward i lines, with a default of one screenful. At end-of-file, more will continue with the next file in the list, or exit if the current file is the last file in the list. ib i<Ctrl-b> Move backward i lines, with a default of one screenful. If i is more than the screen size, only the final screenful will be written. q, Q, :q, :Q, ZZ Exit from more. = :f <Ctrl-g> Write the name of the file currently being examined, the number relative to the total number of files there are to examine, the current line number, the current byte number, and the total bytes to write and what percentage of the file precedes the current position. All of these items reference the first byte of the line after the last line written. v Invoke an editor to edit the current file being examined. The name of the editor is taken from the environment variable EDITOR, or default to vi. If EDITOR represents either vi or ex, the editor is invoked with options such that the current editor line is the physical line corresponding to the current position in more at the time of the invocation. When the editor exits, more resumes on the current file by rewriting the screen with the current line as the current position. h Display a description of all the more commands. i/[!]expression Search forward in the file for the i-th line containing the regular expression expression. The default value for i is 1. The search starts at the line following the current position. If the search is successful, the screen is modified so that the searched-for line is in the current position. The null regular expression (/<Return>) repeats the search using the previous regular expression. If the character ! is included, the lines for searching are those that do not contain expression. If there are less than i occurrences of expression, and the input is a file rather than a pipe, then the position in the file remains unchanged. The user's erase and kill characters can be used to edit the regular expression. Erasing back past the first column cancels the search command. i?[!]expression Same as /, but searches backward in the file for the i th line containing the regular expression expression. in Repeat the previous search for the i-th line (default 1) containing the last expression (or not containing the last expression, if the previous search was /! or ?!). iN Repeat the search for the opposite direction of the previous search for the i-th line (default 1) containing the last expression '' (single quotes) Return to the position from which the last large movement command was executed ( "large movement" is defined as any movement of more than a screenful of lines). If no such movements have been made, return to the beginning of the file. !command Invoke a shell with command. The characters % and ! in command are replaced with the current file name and the previous shell command, respectively. If there is no current file name, % is not expanded. The sequences \% and \! are replaced by % and ! respectively. :e [file] E [file] Examine a new file. If the file argument is not specified, the "current" file (see the :n and :p commands) from the list of files in the command line is re-examined. The filename is subjected to the process of shell word expansions. If file is a # (number sign) character, the previously examined file is re-examined. i:n Examine the next file. If i is specified, examines the i-th next file specified in the command line. i:p Examine the previous file. If a number i is specified, examines the i-th previous file specified in the command line. :t tagstring Go to the supplied tagstring and scroll or rewrite the screen with that line in the current position. m letter Mark the current position with the specified letter, where letter represents the name of one of the lower-case letters of the portable character set. ' letter Return to the position that was previously marked with the specified letter, making that line the current position. r <Ctrl-l> Refresh the screen. R Refresh the screen, discarding any buffered input. The commands take effect immediately; i.e., it is not necessary to press <Return>. Up to the time when the command character itself is given, the line-kill character can be used to cancel the numerical argument being formed. If the standard output is not a teletype, more is equivalent to cat(1). more supports the SIGWINCH signal, and redraws the screen in response to window size changes. EXTERNAL INFLUENCES Environment Variables COLUMNS Overrides the system-selected horizontal screen size. EDITOR Used by the v command to select an editor. LANG Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the default value of "C" (see lang(5)) is used. If any of the internationalization variables contains an invalid setting, more will behave as if all internationalization variables are set to "C". See environ(5). LC_ALL If set to a non-empty string value, overrides the values of all the other internationalization variables. LC_CTYPE Determines the interpretation of text as single and/or multi-byte characters, the classification of characters as printable, and the characters matched by character class expressions in regular expressions. LC_MESSAGES Determines the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. NLSPATH Determines the location of message catalogues for the processing of LC_MESSAGES. LINES Overrides the system-selected vertical screen size, used as the number of lines in a screenful. The -n option takes precedence over the LINES variable for determining the number of lines in a screenful. MORE Determines a string containing options, preceded with hyphens and blank-character-separated as on the command line. Any command-line options are processed after those in the MORE variable. The MORE variable takes precedence over the TERM and LINES variables for determining the number of lines in a screenful. TERM Determines the name of the terminal type. International Code Set Support Single- and multi-byte character code sets are supported. EXAMPLES To view a simple file, use: more filename To preview nroff output, use a command resembling: nroff -mm +2 doc.n | more -s If the file contains tables, use: tbl file | nroff -mm | col | more -s To display file stuff in a fifteen line-window and convert multiple adjacent blank lines into a single blank line: more -s -n 15 stuff To examine each file with its last screenful: more -p G file1 file2 To examine each file starting with line 100 in the current position (third line, so line 98 is the first line written): more -p 100g file1 file2 To examine the file that contains the tagstring tag with line 30 in the current position: more -t tag -p 30g WARNINGS Standard error, file descriptor 2, is normally used for input during interactive use and should not be redirected (see Input/Output section in the manpage of the shell in use). FILES /usr/share/lib/terminfo/?/* compiled terminal capability data base AUTHOR more was developed by Mark Nudleman, University of California, Berkeley, OSF, and HP. SEE ALSO csh(1), man(1), pg(1), sh(1), term(4), terminfo(4), environ(5), lang(5), regexp(5). STANDARDS CONFORMANCE more: XPG4
pg - File-viewing filter.
pg(1) pg(1) NAME pg - file perusal filter for soft-copy terminals SYNOPSIS pg [-number] [-pstring] [-cefns] [+linenumber] [+/pattern] [file ...] Remarks pg and more are both used in similar situations (see more(1)). Text highlighting features supported by more are not available from pg. However, pg has some useful features not provided by more. DESCRIPTION pg is a text file filter that allows the examination of files one screenful at a time on a soft-copy terminal. If - is used as a file argument, or pg detects NULL arguments in the comand line, the standard input is used. Each screenful is followed by a prompt. To display a new page, press Return. Other possibilities are enumerated below. This command is different from other paginators such as more in that it can back up for reviewing something that has already passed. The method for doing this is explained below. In order to determine terminal attributes, pg scans the terminfo data base for the terminal type specified by the environment variable TERM (see terminfo(4)). If TERM is not defined, terminal type dumb is assumed. Options pg recognizes the following command line options: -number number is an integer specifying the size (in lines) of the window that pg is to use instead of the default (on a terminal containing 24 lines, the default window size is 23). -p string Causes pg to use string as the prompt. If the prompt string contains a %d, the first occurrence of %d in the prompt is replaced by the current page number when the prompt is issued. The default prompt string is a colon (:). -c Home the cursor and clear the screen before displaying each page. This option is ignored if clear_screen is not defined in the terminfo data base for this terminal type. -e Causes pg to not pause at the end of each file. -f Normally, pg splits lines longer than the screen width, but some sequences of characters in the text being displayed (such as escape sequences for underlining) generate undesirable results. The -f option inhibits pg from splitting lines. -n Normally, commands must be terminated by a new line character. This option causes an automatic end-of-command as soon as a command letter is entered. -s Causes pg to print all messages and prompts in standout mode (usually inverse video). +linenumber Start display at linenumber. +/pattern/ Start up at the first line containing text that matches the regular expression pattern. pg looks in the environment variable PG to preset any flags desired. For example, if you prefer to view files using the -c mode of operation, the Bourne-shell command sequence PG='-c' ; export PG or the C-shell command setenv PG -c causes all invocations of pg, including invocations by programs such as man and msgs, to use this mode. The command sequence to set up the PG environment variable is normally placed in the user .profile or .cshrc file. The responses that can be typed when pg pauses can be divided into three categories: those causing further perusal, those that search, and those that modify the perusal environment. Commands that cause further perusal normally take a preceding address, an optionally signed number indicating the point from which further text should be displayed. This address is interpreted either in pages or lines, depending on the command. A signed address specifies a point relative to the current page or line; an unsigned address specifies an address relative to the beginning of the file. Each command has a default address that is used if none is provided. Perusal commands and their defaults are as follows: (+1)<newline> or <blank> Displays one page. The address is specified in pages. (+1) l With a relative address, pg simulates scrolling the screen, forward or backward, the number of lines specified. With an absolute address pg prints a screenful beginning at the specified line. (+1) d or ^D Simulates scrolling a half-screen forward or backward. The following perusal commands take no address: . or ^L Typing a single period causes the current page of text to be redisplayed. $ Displays the last windowful in the file. Use with caution when the input is a pipe. The following commands are available for searching for text patterns in the text. The Basic Regular Expression syntax (see regexp(5)) is supported. Regular expressions must always be terminated by a new line character, even if the -n option is specified. i/pattern/ Search forward for the ith (default i=1) occurrence of pattern. Searching begins immediately after the current page and continues to the end of the current file, without wrap- around. i^pattern^ i?pattern? Search backwards for the ith (default i=1) occurrence of pattern. Searching begins immediately before the current page and continues to the beginning of the current file, without wrap-around. The ^ notation is useful for Adds 100 terminals which cannot properly handle the ?. After searching, pg normally displays the line found at the top of the screen. This can be modified by appending m or b to the search command to leave the line found in the middle or at the bottom of the window from now on. The suffix t can be used to restore the original situation. pg users can modify the perusal environment with the following commands: in Begin perusing the ith next file in the command line. The i is an unsigned number, default value is 1. ip Begin perusing the ith previous file in the command line. i is an unsigned number, default is 1. iw Display another window of text. If i is present, set the window size to i. s filename Save the input in the named file. Only the current file being perused is saved. The white space between the s and filename is optional. This command must always be terminated by a new line character, even if the -n option is specified. h Help by displaying an abbreviated summary of available commands. q or Q Quit pg. !command command is passed to the shell, whose name is taken from the SHELL environment variable. If this is not available, the default shell is used. This command must always be terminated by a new line character, even if the -n option is specified. To cause pg to stop sending output and display the prompt at any time when output is being sent to the terminal, press the quit key (normally Ctrl-\) or the interrupt (break) key. Any one of the above commands can then be entered in the normal manner. Unfortunately, some output is lost when this is done, due to the fact that any characters waiting in the terminal's output queue are flushed when the quit signal occurs. If the standard output is not a terminal, pg is functionally equivalent to cat (see cat(1)), except that a header is printed before each file if more than one file is specified. EXTERNAL INFLUENCES Environment Variables LC_COLLATE determines the collating sequence used in evaluating regular expressions. LC_CTYPE determines the interpretation of text as single and/or multi-byte characters, and the characters matched by character class expressions in regular expressions. LANG determines the language in which messages are displayed. If LC_COLLATE or LC_CTYPE is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable. If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG. If any internationalization variable contains an invalid setting, pg behaves as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single- and multi-byte character code sets are supported. EXAMPLEs To use pg when reading system news: news | pg -p "(Page %d):" WARNINGS If terminal tabs are not set every eight positions, undesirable results may occur. When using pg as a filter with another command that changes the terminal I/O options (such as crypt(1)), terminal settings may not be restored correctly. While waiting for terminal input, pg responds to BREAK, DEL, and ^ by terminating execution. Between prompts, however, these signals interrupt pg's current task and place the user in prompt mode. These should be used with caution when input is being read from a pipe, because an interrupt is likely to terminate the other commands in the pipeline. Users of more will find that the z and f commands are available, and that the terminal /, ^, or ? can be omitted from the pattern search commands. FILES /usr/share/lib/terminfo/?/* terminal information data base /tmp/pg* temporary file when input is from a pipe SEE ALSO crypt(1), grep(1), more(1), terminfo(4), environ(5), lang(5), regexp(5). STANDARDS CONFORMANCE pg: SVID2, SVID3, XPG2, XPG3
tail - Produce the last part of a file.
tail(1) tail(1) NAME tail - deliver the last part of a file SYNOPSIS tail [-f] [-b number] [file] tail [-f] [-c number] [file] tail [-f] [-n number] [file] Obsolescent: tail [+-[number][l|b|c] [-f] [file] DESCRIPTION tail copies the named file to the standard output beginning at a designated place. If no file is named, standard input is used. Command Forms tail can be used in three forms as indicated above: tail -b number... Copy file starting at number blocks from end or beginning of file. tail -c number... Copy file starting at number bytes from end or beginning of file. tail -n number... or tail number... Copy file starting at number lines from end or beginning of file. tail with no options specified is equivalent to tail -n 10.... Options and Command-Line Arguments tail recognizes the following options and command-line arguments: -f Follow option. If the input file is a regular file or if file specifies a FIFO, do not terminate after the last line of the input file has been copied, but read and copy further bytes from the input file when they become available (tail enters an endless loop wherein it sleeps for one second then attempts to read and copy further records from the input file). This is useful when monitoring text being written to a file by another process. If no file argument is specified and the input is a pipe (FIFO), the -f option is ignored. number Decimal integer indicating quantity of output to be copied, measured in units specified by accompanying option. If number is preceded by a + character, copy operation starts number units from beginning of file. If number is preceded by a - character or the option name, copy operation starts number units from end of file. If number is not preceded by a b, c, or n option, -n is assumed. If both the option and number are not specified, -n 10 is assumed. -b number Copy file beginning number 512-byte blocks from end or beginning of file. If number is not specified, -b 10 is assumed. See number description above. -c number Copy file beginning number bytes from end or beginning of file. If number is not specified, -c 10 is assumed. See number description above. -n number Copy file beginning number lines from end or beginning of file. If number is not specified, -n 10 is assumed. See number description above. file Name of file to be copied. If not specified, the standard input is used. If the -c option is specified, the input file can contain arbitrary data. Otherwise, the input file should be a text file. Obsolescent Form In the obsolescent form, option letters can be concatenated after the number argument to select blocks, bytes, or lines. If this syntax is used, +-number must be the first argument given. If number is not specified, -10 is assumed. This version is provided for backward compatibility only. The forms discussed previously are recommended for portability. EXTERNAL INFLUENCES Environment Variables LC_CTYPE determines the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte characters in arguments and input files). LC_MESSAGES determines the language in which messages are displayed. If LC_CTYPE or LC_MESSAGES is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable. If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG. If any internationalization variable contains an invalid setting, tail behaves as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single- and multi-byte character code sets are supported. However, the b and c options can break multi-byte characters and should be used with caution in a multi-byte locale environment. EXAMPLES Print the last three lines in file file1 to the standard output, and leave tail in ``follow'' mode: tail -fn 3 file1 or tail -3 -f file1 Print the last 15 bytes of file logfile followed by any lines that are appended to logfile after tail is initiated until it is killed: tail -fc15 logfile or tail -f -c 15 logfile Three ways to print an entire file: tail -b +1 file tail -c +1 file tail -n +1 file WARNINGS Tails relative to end-of-file are stored in a 20-Kbyte buffer, and thus are limited in length. Therefore, be wary of the results when piping output from other commands into tail. Various kinds of anomalous behavior may occur with character special files. SEE ALSO dd(1), head(1). STANDARDS CONFORMANCE tail: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
CONTENTS |