tail prints the contents of the specified file on standard output beginning at a designated place. If no file name is specified, tail outputs the contents of standard input. If tail is used with a character-oriented special file a problem may occur.
Syntax
Format 1: |
tail[ -f][ -c place | -n place][ file] |
Format 2: |
tail[ +|-[place][l|b|c][f]][ file] |
(follow) If the input file is not a pipe, the program will not terminate after the last line of the input file has been displayed, but will enter an endless loop, wherein it sleeps for at least a second and then attempts to read and copy further records from the input file. You could thus use this option to monitor the growth of a file that is being written by some other process. -f is ignored if no file is specified file and the standard input is a pipe.
(character) The output of the tail starts at the character defined by place. [[ number can be specified as any decimal integer value. +number is calculated relative Caution! +|- not specified: number not specified: place not specified:
(number) This option is equivalent to -c place except that the output is counted line by line not byte by byte.
Name of the input file to be displayed by tail. file not specified: |
You use place to specify the position in the input file at which you want output to start. Enter a decimal integer value for place. If you enter +[place] counting starts at the beginning of the file. If you enter -[place] the command counts from the end of the file. Caution! place not specified: No space character is allowed between +[place] or -[ place ] and the unit ( l , b or c ).
(line) Starts display at the line defined by place.
(block) Starts display at the block defined by place. A block is a 512-byte unit.
(character) Starts display at the character defined by place.
(follow) If the input file is not a pipe, the program will not terminate after the last line of the input file has been displayed, but will enter an endless loop, wherein it sleeps for at least a second and then attempts to read and copy further records from the input file. You could thus use this option to monitor the growth of a file that is being written by some other process.
Name of the input file to be displayed by tail. file not specified: |
Locale
The following environment variables affect the execution of tail: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. |
Example 1
The file months contains the name of a month in each line. The following two calls to tail:
will result in the same output:
|
Example 2
To observe the effect of the -f option, create a shell script that writes data to a file in an endless loop and run this script in the background. The shell script neverend with the following contents would serve the purpose: while true do { date >>anne sleep 5 } done You can now run this script in the background and then call tail with option -f and the file anne as its argument:
tail first displays the last five lines of the file anne, followed by the data written to this file by the script neverend. The process generated with tail -f can be terminated by pressing CTRL+C (or @@c in the case of block terminals). |
See also
cat, head, more |