|Previous||Table of Contents||Next|
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.
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
|tail [ -[n]bcflr ] file_list
tail [ +[n]bcflr ] file_list
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.|
|Display n blocks of text instead of n lines.|
|Display n characters of text instead of n lines.|
|Display n lines of text. This is the default if no text type option is provided.|
|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.|
|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.|
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.
Refer to the cat, head, and pg commands described in modules 13, 63, and 109.
The tail command can read from the standard input or files. It writes to the standard output.
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.
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.
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.
|Previous||Table of Contents||Next|