1TAIL(1P)                   POSIX Programmer's Manual                  TAIL(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       tail — copy the last part of a file
13

SYNOPSIS

15       tail [-f] [-c number|-n number] [file]
16

DESCRIPTION

18       The tail utility shall copy its  input  file  to  the  standard  output
19       beginning at a designated place.
20
21       Copying shall begin at the point in the file indicated by the -c number
22       or -n number options. The option-argument number shall  be  counted  in
23       units of lines or bytes, according to the options -n and -c.  Both line
24       and byte counts start from 1.
25
26       Tails relative to the end of the file may be saved in an internal  buf‐
27       fer, and thus may be limited in length. Such a buffer, if any, shall be
28       no smaller than {LINE_MAX}*10 bytes.
29

OPTIONS

31       The tail utility shall  conform  to  the  Base  Definitions  volume  of
32       POSIX.1‐2017,  Section 12.2, Utility Syntax Guidelines, except that '+'
33       may be recognized as an option delimiter as well as '-'.
34
35       The following options shall be supported:
36
37       -c number The application shall ensure that the number  option-argument
38                 is  a decimal integer, optionally including a sign.  The sign
39                 shall affect the location in the file, measured in bytes,  to
40                 begin the copying:
41
42                        ┌─────┬────────────────────────────────────────┐
43Sign Copying Starts             
44                        ├─────┼────────────────────────────────────────┤
45                        │ +   │ Relative to the beginning of the file. │
46                        │ -   │ Relative to the end of the file.       │
47none │ Relative to the end of the file.       │
48                        └─────┴────────────────────────────────────────┘
49                 The  application  shall ensure that if the sign of the number
50                 option-argument is '+', the number option-argument is a  non-
51                 zero decimal integer.
52
53                 The origin for counting shall be 1; that is, -c +1 represents
54                 the first byte of the file, -c -1 the last.
55
56       -f        If the input file is a regular file or if  the  file  operand
57                 specifies a FIFO, do not terminate after the last line of the
58                 input file has been copied, but read and copy  further  bytes
59                 from  the  input  file when they become available. If no file
60                 operand is specified and standard input is a  pipe  or  FIFO,
61                 the  -f  option  shall be ignored. If the input file is not a
62                 FIFO, pipe, or regular file, it is unspecified whether or not
63                 the -f option shall be ignored.
64
65       -n number This  option  shall  be  equivalent  to -c number, except the
66                 starting location in the file  shall  be  measured  in  lines
67                 instead  of  bytes.  The origin for counting shall be 1; that
68                 is, -n +1 represents the first line of the file,  -n  -1  the
69                 last.
70
71       If neither -c nor -n is specified, -n 10 shall be assumed.
72

OPERANDS

74       The following operand shall be supported:
75
76       file      A pathname of an input file. If no file operand is specified,
77                 the standard input shall be used.
78

STDIN

80       The standard input shall be used if no file operand is  specified,  and
81       shall  be used if the file operand is '-' and the implementation treats
82       the '-' as meaning standard input.  Otherwise, the standard input shall
83       not be used.  See the INPUT FILES section.
84

INPUT FILES

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

ENVIRONMENT VARIABLES

90       The following environment variables shall affect the execution of tail:
91
92       LANG      Provide a default value for  the  internationalization  vari‐
93                 ables  that are unset or null. (See the Base Definitions vol‐
94                 ume of POSIX.1‐2017, Section 8.2, Internationalization  Vari‐
95                 ables  for  the  precedence of internationalization variables
96                 used to determine the values of locale categories.)
97
98       LC_ALL    If set to a non-empty string value, override  the  values  of
99                 all the other internationalization variables.
100
101       LC_CTYPE  Determine  the  locale for the interpretation of sequences of
102                 bytes of text data as characters (for example, single-byte as
103                 opposed  to  multi-byte  characters  in  arguments  and input
104                 files).
105
106       LC_MESSAGES
107                 Determine the locale that should be used to affect the format
108                 and  contents  of  diagnostic  messages  written  to standard
109                 error.
110
111       NLSPATH   Determine the location of message catalogs for the processing
112                 of LC_MESSAGES.
113

ASYNCHRONOUS EVENTS

115       Default.
116

STDOUT

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

STDERR

122       The standard error shall be used only for diagnostic messages.
123

OUTPUT FILES

125       None.
126

EXTENDED DESCRIPTION

128       None.
129

EXIT STATUS

131       The following exit values shall be returned:
132
133        0    Successful completion.
134
135       >0    An error occurred.
136

CONSEQUENCES OF ERRORS

138       Default.
139
140       The following sections are informative.
141

APPLICATION USAGE

143       The -c option should be used with caution when the input is a text file
144       containing  multi-byte  characters; it may produce output that does not
145       start on a character boundary.
146
147       Although the input file to tail can be any type, the results might  not
148       be  what would be expected on some character special device files or on
149       file  types  not  described  by  the  System   Interfaces   volume   of
150       POSIX.1‐2017.  Since  this  volume of POSIX.1‐2017 does not specify the
151       block size used when doing input, tail need not read all  of  the  data
152       from devices that only perform block transfers.
153
154       When  using  tail to process pathnames, and the -c option is not speci‐
155       fied, it is recommended that LC_ALL, or at least LC_CTYPE  and  LC_COL‐
156       LATE,  are  set  to  POSIX or C in the environment, since pathnames can
157       contain byte sequences that  do  not  form  valid  characters  in  some
158       locales,  in  which  case the utility's behavior would be undefined. In
159       the POSIX locale each byte is a valid single-byte character, and there‐
160       fore this problem is avoided.
161

EXAMPLES

163       The -f option can be used to monitor the growth of a file that is being
164       written by some other process. For example, the command:
165
166
167           tail -f fred
168
169       prints the last ten lines of the file fred, followed by any lines  that
170       are  appended to fred between the time tail is initiated and killed. As
171       another example, the command:
172
173
174           tail -f -c 15 fred
175
176       prints the last 15 bytes of the file fred, followed by any  bytes  that
177       are appended to fred between the time tail is initiated and killed.
178

RATIONALE

180       This  version  of  tail was created to allow conformance to the Utility
181       Syntax Guidelines. The historical -b option was omitted because of  the
182       general  non-portability  of  block-sized  units of text. The -c option
183       historically meant ``characters'',  but  this  volume  of  POSIX.1‐2017
184       indicates  that  it means ``bytes''. This was selected to allow reason‐
185       able implementations when multi-byte characters are  possible;  it  was
186       not named -b to avoid confusion with the historical -b.
187
188       The  origin  of  counting both lines and bytes is 1, matching all wide‐
189       spread historical implementations. Hence tail -n +0 is  not  conforming
190       usage  because it attempts to output line zero; but note that tail -n 0
191       does conform, and outputs nothing.
192
193       Earlier versions of this standard allowed the following  forms  in  the
194       SYNOPSIS:
195
196
197           tail -[number][b|c|l][f] [file]
198           tail +[number][b|c|l][f] [file]
199
200       These forms are no longer specified by POSIX.1‐2008, but may be present
201       in some implementations.
202
203       The restriction on the internal buffer is a compromise between the his‐
204       torical System V implementation of 4096 bytes and the BSD 32768 bytes.
205
206       The  -f  option has been implemented as a loop that sleeps for 1 second
207       and copies any bytes that are available. This  is  sufficient,  but  if
208       more  efficient  methods of determining when new data are available are
209       developed, implementations are encouraged to use them.
210
211       Historical documentation indicates that tail ignores the -f  option  if
212       the input file is a pipe (pipe and FIFO on systems that support FIFOs).
213       On BSD-based systems, this has been true; on  System  V-based  systems,
214       this  was true when input was taken from standard input, but it did not
215       ignore the -f flag if a FIFO was named as the file operand.  Since  the
216       -f  option  is  not  useful on pipes and all historical implementations
217       ignore -f if no file operand is specified and standard input is a pipe,
218       this  volume of POSIX.1‐2017 requires this behavior. However, since the
219       -f option is useful  on  a  FIFO,  this  volume  of  POSIX.1‐2017  also
220       requires  that  if a FIFO is named, the -f option shall not be ignored.
221       Earlier versions of this standard did not state any requirement for the
222       case  where  no file operand is specified and standard input is a FIFO.
223       The standard has been updated to reflect current practice which  is  to
224       treat this case the same as a pipe on standard input.  Although histor‐
225       ical behavior does not ignore the -f option for other file types,  this
226       is  unspecified  so  that  implementations are allowed to ignore the -f
227       option if it is known that the file cannot be extended.
228

FUTURE DIRECTIONS

230       None.
231

SEE ALSO

233       head
234
235       The Base Definitions volume of  POSIX.1‐2017,  Chapter  8,  Environment
236       Variables, Section 12.2, Utility Syntax Guidelines
237
239       Portions  of  this text are reprinted and reproduced in electronic form
240       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
241       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
242       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
243       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
244       event of any discrepancy between this version and the original IEEE and
245       The  Open Group Standard, the original IEEE and The Open Group Standard
246       is the referee document. The original Standard can be  obtained  online
247       at http://www.opengroup.org/unix/online.html .
248
249       Any  typographical  or  formatting  errors that appear in this page are
250       most likely to have been introduced during the conversion of the source
251       files  to  man page format. To report such errors, see https://www.ker
252       nel.org/doc/man-pages/reporting_bugs.html .
253
254
255
256IEEE/The Open Group                  2017                             TAIL(1P)
Impressum