TAIL(1) General Commands Manual TAIL(1)

tailcopy the last part of a file

tail [−f] [ −c number | −n number ] [file]
Obsolescent versions:
tail    −[number][c| l][f] [file]
tail    +[number][c| l][f] [file]

The tail utility shall copy its input file to the standard output beginning at a designated place. Copying shall begin at the point in the file indicated by the −c number or −n number options (or the ±number portion of the argument to the obsolescent version). The option-argument number shall be counted in units of lines or bytes, according to the options −n and −c (or, in the obsolescent version, the appended option suffixes l or c). Tails relative to the end of the file may be saved in an internal buffer, and thus may be limited in length. Implementations shall ensure that such a buffer, if any, is no smaller than ∗10 bytes.

The tail utility shall conform to the utility argument syntax guidelines described in standard described in 2.10.2, except that the obsolescent version accepts multicharacter options that can preceded by a plus sign. The following options shall be supported by the implementation in the nonobsolescent version:

number

The number option-argument shall be a decimal integer whose sign affects the location in the file, measured in bytes, to begin the copying:

Sign

Copying Starts + Relative to the beginning of the file. − Relative to the end of the file. none Relative to the end of the file.

The origin for counting shall be 1; i.e., -c +1 represents the first byte of the file, -c -1 the last.

If the input file is a regular file or if the file operand 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. If no file operand is specified and standard input is a pipe, the −f option shall be ignored. If the input file is not a FIFO, pipe, or regular file, it is unspecified whether or not the −f option shall be ignored.

number

This option shall be equivalent to −c number, except the starting location in the file shall be measured in lines instead of bytes. The origin for counting shall be 1; i.e., -n +1 represents the first line of the file, -n -1 the last.

In the obsolescent version, an argument beginning with a - or + can be used as a single option. The argument ±number with the letter c specified as a suffix shall be equivalent to −c ±number; ±number with the letter l specified as a suffix, or with neither c nor l as a suffix, shall be equivalent to −n ±number. If number is not specified in these forms, 10 shall be used. The letter f specified as a suffix shall be equivalent to specifying the −f option. If the -[number]c[f] form is used and neither number nor the f suffix is specified, it shall be interpreted as the

number option. In the nonobsolescent form, if neither −c nor −n is specified, -n 10 shall be assumed.

The following operand shall be supported by the implementation:

file

A pathname of an input file. If no file operands are specified, the standard input shall be used.

The standard input shall be used only if no file operands are specified. See Input Files.

If the −c option is specified, the input file can contain arbitrary data; otherwise, the input file shall be a text file.

The following environment variables shall affect the execution of tail:

This variable shall determine the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_ ) do not specify a locale. See 2.6.

This variable shall determine the locale to be used to override any values for locale categories specified by the settings of LANG or any environment variables beginning with LC_.

This variable shall determine 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).

This variable shall determine the language in which messages should be written.

Default.

The designated portion of the input file shall be written to standard output.

Used only for diagnostic messages.

None.

None.

The tail utility shall exit with one of the following values:

Successful completion.

An error occurred.

Default.

Usage, Examples

The nonobsolescent version of tail was created to allow conformance to the Utility Syntax Guidelines. The historical −b option was omitted because of the general nonportability of block-sized units of text. The −c option historically meant ‘‘characters,’’ but this standard indicates that it means ‘‘bytes.’’ This was selected to allow reasonable implementations when multibyte characters are possible; it was not named −b to avoid confusion with the historical −b. Note that the −c option should be used with caution when the input is a text file containing multibyte characters; it may produce output that does not start on a character boundary. The origin of counting both lines and bytes is 1, matching all widespread historical implementations.

The restriction on the internal buffer is a compromise between the historical System V implementation of 4K and the BSD 32K. The −f option can be used to monitor the growth of a file that is being written by some other process. For example, the command: tail −f fred prints the last ten lines of the file fred, followed by any lines that are appended to fred between the time tail is initiated and killed. As another example, the command: tail −f -c 15 fred prints the last 15 bytes of the file fred, followed by any bytes that are appended to fred between the time tail is initiated and killed. Although the input file to tail can be any type, the results need not be what would be expected on some character special device files or on file types not described by POSIX. 1 {8}. Since the standard does not specify the block size used when doing input, tail need not read all of the data from devices that only perform block transfers.

The developers of the standard originally decided that tail, and its frequent companion, head, were useful mostly to interactive users, and not application programs. However, balloting input suggested that these utilities actually do find significant use in scripts, such as to write out portions of log files. The balloters also challenged the working group’s assumption that clever use of sed could be an appropriate substitute for tail. The −f option has been implemented as a loop that sleeps for one second and copies any bytes that are available. This is sufficient, but if more efficient methods of determining when new data are available are developed, implementations are encouraged to use them. Historical documentation says that tail ignores the −f option if the input file is a pipe (pipe and FIFO on systems that support FIFOs). On BSD -based systems, this has been true; on System V-based systems, this was true when input was taken from standard input, but behaved as on other files if a FIFO was named as the file operand. Since the −f option is not useful on pipes and all historical implementations ignore −f if no file operand is specified and standard input is a pipe, POSIX. 2 requires this behavior. However, since the −f option is useful on a FIFO, POSIX. 2 also requires that if standard input is a FIFO or a FIFO is named, the −f option shall not be ignored. Although historical behavior does not ignore the −f option for other file types, this is unspecified so that implementations are allowed to ignore the −f option if it is known that the file cannot be extended. An earlier draft had the synopsis line:

tail [ −c | −l ] [−f] [−n number] [file] This was changed to the current form based on comments and objections noting that −c was almost never used without specifying a number and there was no need to specify −l if −n number was given.

September 1991 posix.fail