Module 131 tail

Previous Table of Contents Next


Module 131
tail

DESCRIPTION

The external tail command displays the last few lines of a file. It displays however many lines you specify as an option. If you do not specify a number of lines, tail displays the last ten lines of a file. Its cousin is the head command.

The tail command also provides an automatic displaying mode. You may have a process that generates output to a log file and you want to watch the log as the process executes. By using the -f option, tail displays each new line in the file. This provides you the flexibility to watch the file when you want to for however long you desire .

COMMAND FORMAT

The general format of the tail command follows .

 tail [ -[n]bcfl ] file_list      tail [ +[n]bcfl ] file_list      tail [ -[n]bcrl ] file_list      tail [ +[n]bcrl ] file_list 

BSD (Berkeley)
tail [ -[n]bcflr ] file_list
tail [ +[n]bcflr ] file_list

Options

The following list describes the options and their arguments that may be used to control how tail functions.

- n The number of lines tail will display from the end of the file. If n is not provided, tail displays the last ten lines of the file.%
+ n The number of lines tail will skip from the beginning of the file before it starts to display lines. If n is not given, tail skips ten lines.
- n b
+ n b
Display n blocks of text instead of n lines.
- n c
+ n c
Display n characters of text instead of n lines.
- n l
+ n l
Display n lines of text. This is the default if no text type option is provided.
- n f
+ n f
Follow the growth of a file. After the tail command has read and displayed the requested lines of data it enters an endless loop. It waits one second then checks for additional lines added to the file. If new lines have been added by another process, then it displays them. It continues this sleep and check process until you terminate it. If you are executing tail interactively, the interrupt signal causes termination. If tail is running in the background, then use the kill command to terminate it. This option allows you to monitor the growth of a file being written to by another process. The file tail is reading must not be a pipe.
- n r
+ n r
Displays lines from the end of the file in reverse order. The last line of the file is displayed first. If you do not specify n , the entire file is displayed.

Arguments

The following argument may be passed to the tail command.

file_list A list of files that tail will display the last n (10) lines of to your screen.

DIAGNOSTICS AND BUGS

If the - n option is used, tail stores the text of the file in a buffer until the end-of-file is read. It can then display the requested amount of lines relative to the last line. Because it buffers the data, tail is limited to certain file sizes.

If you use tail with character special files it may behave strangely.

RELATED COMMANDS

Refer to the cat , head , and pg commands described in modules 13, 63, and 109.

RELATED FILES

The tail command can read from the standard input or files. It writes to the standard output.

APPLICATIONS

The tail command is useful when you only need to view the last few lines of a large file. It can be used to see if ASCII files were completed correctly by another process. For example, if you transmit a file across telephone lines, you can use tail to see if the file ends correctly.

It can also be used to monitor the progress of another process. If the other process is writing output to a file, tail with the -f option can be used to display the lines of the file as the other process writes them.

TYPICAL OPERATION

In this activity you use the tail command to display the last five lines of a file and all lines after line 4. Begin at the shell prompt.

1.    Type tail -5 file2 and press Return . Notice the last 5 lines of the file2 file is displayed.
2.    Type tail +5 file2 and press Return . tail skips to line five before it begins to display the contents. Your screen should look like the following display:
 cj> tail +5 file2           Just a few control Keys for demonstration.      =====      This text is being read by cat from my terminal keyboard.      Cat will read the text as it is typed and create a file named file1.      With a blank third line!           Just a few control keys for demonstration. 
3.     Turn to Module 103 (SV), Module 90 (BSD) to continue the learning sequence.


Previous Table of Contents Next

Copyright Wordware Publishing, Inc.


Illustrated UNIX System V
Illustrated Unix System V/Bsd
ISBN: 1556221878
EAN: 2147483647
Year: N/A
Pages: 144
Authors: Robert Felps

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net