Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

tail - deliver the last part of a file

&pagelevel(4)&pagelevel

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]
Format 1: tail[ -f][ -c place | -n place][ file]


-f

(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.

-c place

(character)

The output of the tail starts at the character defined by place.
You use place to specify the position in the input file at which you want output to start:

[[ + | - ]number]

number can be specified as any decimal integer value. +number is calculated relative
to the beginning of the file; -number is calculated relative to the end of the file.


Caution!
Tails relative to the end of the file are buffered by tail and are thus restricted to a maximum of 4 Kbytes.


+|- not specified:
tail calculates relative to the end of the file.

number not specified:
The default value of 10 is assumed.

place not specified:
The default value for place is -10, i.e. 10 lines from the end of the file.

-n place

(number)

This option is equivalent to -c place except that the output is counted line by line not byte by byte.

file

Name of the input file to be displayed by tail.

file not specified:
tail reads from standard input.

Format 2: tail[ +|-[place][l|b|c][f]][ file]


place

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!
tail buffers sections which are read from the end of the file. The size of this buffer is limited to 4 kbytes.


place not specified:
The default value is 10, i.e. 10 units counted from the start or from the end of the file.


No space character is allowed between +[place] or -[ place ] and the unit ( l , b or  c ).


l

(line)

Starts display at the line defined by place.

b

(block)

Starts display at the block defined by place. A block is a 512-byte unit.

c

(character)

Starts display at the character defined by place.

f

(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.


file

Name of the input file to be displayed by tail.

file not specified:
tail reads from standard input.

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:

$ tail -n 5 months

$ tail -n +8 months

will result in the same output:

August
September
October
November
December

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:

$ neverend&

656

$ tail -n -5 -f anne
These five

lines

were already

in the file

before any additions.

FRI JAN 23 11:40:35 MEZ 2009

FRI JAN 23 11:40:40 MEZ 2009

...

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