xref: /freebsd/usr.bin/tail/tail.1 (revision 4f8f43b06ed07e96a250855488cc531799d5b78f)
1.\" Copyright (c) 1980, 1990, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the Institute of Electrical and Electronics Engineers, Inc.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"	@(#)tail.1	8.1 (Berkeley) 6/6/93
32.\"
33.Dd July 12, 2022
34.Dt TAIL 1
35.Os
36.Sh NAME
37.Nm tail
38.Nd display the last part of a file
39.Sh SYNOPSIS
40.Nm
41.Op Fl F | f | r
42.Op Fl qv
43.Oo
44.Fl b Ar number | Fl c Ar number | Fl n Ar number
45.Oc
46.Op Ar
47.Sh DESCRIPTION
48The
49.Nm
50utility displays the contents of
51.Ar file
52or, by default, its standard input, to the standard output.
53.Pp
54The display begins at a byte, line or 512-byte block location in the
55input.
56Numbers having a leading plus
57.Pq Ql +
58sign are relative to the beginning
59of the input, for example,
60.Dq Li "-c +2"
61starts the display at the second
62byte of the input.
63Numbers having a leading minus
64.Pq Ql -
65sign or no explicit sign are
66relative to the end of the input, for example,
67.Dq Li "-n 2"
68displays the last two lines of the input.
69The default starting location is
70.Dq Li "-n 10" ,
71or the last 10 lines of the input.
72.Pp
73The options are as follows:
74.Bl -tag -width indent
75.It Fl b Ar number , Fl -blocks Ns = Ns Ar number
76The location is
77.Ar number
78512-byte blocks.
79.It Fl c Ar number , Fl -bytes Ns = Ns Ar number
80The location is
81.Ar number
82bytes.
83.It Fl f
84The
85.Fl f
86option causes
87.Nm
88to not stop when end of file is reached, but rather to wait for additional
89data to be appended to the input.
90The
91.Fl f
92option is ignored if the standard input is a pipe, but not if it is a FIFO.
93.It Fl F
94The
95.Fl F
96option implies the
97.Fl f
98option, but
99.Nm
100will also check to see if the file being followed has been renamed or rotated.
101The file is closed and reopened when
102.Nm
103detects that the filename being read from has a new inode number.
104.Pp
105If the file being followed does not (yet) exist or if it is removed, tail
106will keep looking and will display the file from the beginning if and when
107it is created.
108.Pp
109The
110.Fl F
111option is the same as the
112.Fl f
113option if reading from standard input rather than a file.
114.It Fl n Ar number , Fl -lines Ns = Ns Ar number
115The location is
116.Ar number
117lines.
118.It Fl q, Fl -quiet, Fl -silent
119Suppresses printing of headers when multiple files are being examined.
120.It Fl r
121The
122.Fl r
123option causes the input to be displayed in reverse order, by line.
124Additionally, this option changes the meaning of the
125.Fl b , c
126and
127.Fl n
128options.
129When the
130.Fl r
131option is specified, these options specify the number of bytes, lines
132or 512-byte blocks to display, instead of the bytes, lines or blocks
133from the beginning or end of the input from which to begin the display.
134The default for the
135.Fl r
136option is to display all of the input.
137.It Fl v, Fl -verbose
138Prepend each file with a header.
139.El
140.Pp
141If more than a single file is specified, or if the
142.Fl v
143option is used, each file is preceded by a
144header consisting of the string
145.Dq Li "==> " Ns Ar XXX Ns Li " <=="
146where
147.Ar XXX
148is the name of the file.
149The
150.Fl q
151flag disables the printing of the header in all cases.
152.Pp
153All
154.Ar number
155arguments may also be specified with size suffixes supported by
156.Xr expand_number 3 .
157.Sh EXIT STATUS
158.Ex -std
159.Sh EXAMPLES
160To display the last 500 lines of the file
161.Ar foo :
162.Pp
163.Dl $ tail -n 500 foo
164.Pp
165Keep
166.Pa /var/log/messages
167open, displaying to the standard output anything appended to the file:
168.Pp
169.Dl $ tail -F /var/log/messages
170.Sh SEE ALSO
171.Xr cat 1 ,
172.Xr head 1 ,
173.Xr sed 1 ,
174.Xr expand_number 3
175.Sh STANDARDS
176The
177.Nm
178utility is expected to be a superset of the
179.St -p1003.2-92
180specification.
181In particular, the
182.Fl F ,
183.Fl b
184and
185.Fl r
186options are extensions to that standard.
187.Pp
188The historic command line syntax of
189.Nm
190is supported by this implementation.
191The only difference between this implementation and historic versions
192of
193.Nm ,
194once the command line syntax translation has been done, is that the
195.Fl b ,
196.Fl c
197and
198.Fl n
199options modify the
200.Fl r
201option, i.e.,
202.Dq Li "-r -c 4"
203displays the last 4 characters of the last line
204of the input, while the historic tail (using the historic syntax
205.Dq Li -4cr )
206would ignore the
207.Fl c
208option and display the last 4 lines of the input.
209.Sh HISTORY
210A
211.Nm
212command appeared in PWB UNIX.
213