tail - copy the last part of a file
tail [-f][ -c number| -n number][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. The option-argument number shall be counted in units of lines or bytes, according to the options -n and -c. Both line and byte counts start from 1.
Tails relative to the end of the file may be saved in an internal buffer, and thus may be limited in length. Such a buffer, if any, shall be no smaller than {LINE_MAX}*10 bytes.
The tail utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
The following options shall be supported:
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; that is, -c +1 represents the first byte of the file, -c -1 the last.
If neither -c nor -n is specified, -n 10 shall be assumed.
The following operand shall be supported:
The standard input shall be used only if no file operands are specified. See the INPUT FILES section.
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:
The designated portion of the input file shall be written to standard output.
The standard error shall be used only for diagnostic messages.
The following exit values shall be returned:
Default.
The following sections are informative.
The -c option should be used with caution when the input is a text file containing multi-byte characters; it may produce output that does not start on a character boundary.
Although the input file to tail can be any type, the results might not be what would be expected on some character special device files or on file types not described by the System Interfaces volume of IEEE Std 1003.1-2001. Since this volume of IEEE Std 1003.1-2001 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 -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.
This version of tail was created to allow conformance to the Utility Syntax Guidelines. The historical -b option was omitted because of the general non-portability of block-sized units of text. The -c option historically meant "characters", but this volume of IEEE Std 1003.1-2001 indicates that it means "bytes". This was selected to allow reasonable implementations when multi-byte characters are possible; it was not named -b to avoid confusion with the historical -b.
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 4096 bytes and the BSD 32768 bytes.
The -f option has been implemented as a loop that sleeps for 1 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 indicates 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 it did not ignore the -f flag 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, this volume of IEEE Std 1003.1-2001 requires this behavior. However, since the -f option is useful on a FIFO, this volume of IEEE Std 1003.1-2001 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.
This was changed to the current form based on comments noting that -c was almost never used without specifying a number and that there was no need to specify -l if -n number was given.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |