xref: /freebsd/usr.bin/tail/tail.1 (revision 61e21613)
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.Dd November 28, 2023
32.Dt TAIL 1
33.Os
34.Sh NAME
35.Nm tail
36.Nd display the last part of a file
37.Sh SYNOPSIS
38.Nm
39.Op Fl F | f | r
40.Op Fl qv
41.Oo
42.Fl b Ar number | Fl c Ar number | Fl n Ar number
43.Oc
44.Op Ar
45.Sh DESCRIPTION
46The
47.Nm
48utility displays the contents of
49.Ar file
50or, by default, its standard input, to the standard output.
51.Pp
52The display begins at a byte, line or 512-byte block location in the
53input.
54Numbers having a leading plus
55.Pq Ql +
56sign are relative to the beginning
57of the input, for example,
58.Dq Li "-c +2"
59starts the display at the second
60byte of the input.
61Numbers having a leading minus
62.Pq Ql -
63sign or no explicit sign are
64relative to the end of the input, for example,
65.Dq Li "-n 2"
66displays the last two lines of the input.
67The default starting location is
68.Dq Li "-n 10" ,
69or the last 10 lines of the input.
70.Pp
71The options are as follows:
72.Bl -tag -width indent
73.It Fl b Ar number , Fl -blocks Ns = Ns Ar number
74The location is
75.Ar number
76512-byte blocks.
77.It Fl c Ar number , Fl -bytes Ns = Ns Ar number
78The location is
79.Ar number
80bytes.
81.It Fl f
82The
83.Fl f
84option causes
85.Nm
86to not stop when end of file is reached, but rather to wait for additional
87data to be appended to the input.
88The
89.Fl f
90option is ignored if the standard input is a pipe, but not if it is a FIFO.
91.It Fl F
92The
93.Fl F
94option implies the
95.Fl f
96option, but
97.Nm
98will also check to see if the file being followed has been renamed or rotated.
99The file is closed and reopened when
100.Nm
101detects that the filename being read from has a new inode number.
102.Pp
103If the file being followed does not (yet) exist or if it is removed, tail
104will keep looking and will display the file from the beginning if and when
105it is created.
106.Pp
107The
108.Fl F
109option is the same as the
110.Fl f
111option if reading from standard input rather than a file.
112.It Fl n Ar number , Fl -lines Ns = Ns Ar number
113The location is
114.Ar number
115lines.
116.It Fl q , Fl -quiet , Fl -silent
117Suppresses printing of headers when multiple files are being examined.
118.It Fl r
119The
120.Fl r
121option causes the input to be displayed in reverse order, by line.
122Additionally, this option changes the meaning of the
123.Fl b , c
124and
125.Fl n
126options.
127When the
128.Fl r
129option is specified, these options specify the number of bytes, lines
130or 512-byte blocks to display, instead of the bytes, lines or blocks
131from the beginning or end of the input from which to begin the display.
132The default for the
133.Fl r
134option is to display all of the input.
135.It Fl v , Fl -verbose
136Prepend each file with a header.
137.El
138.Pp
139If more than a single file is specified, or if the
140.Fl v
141option is used, each file is preceded by a
142header consisting of the string
143.Dq Li "==> " Ns Ar XXX Ns Li " <=="
144where
145.Ar XXX
146is the name of the file.
147The
148.Fl q
149flag disables the printing of the header in all cases.
150.Pp
151All
152.Ar number
153arguments may also be specified with size suffixes supported by
154.Xr expand_number 3 .
155.Sh EXIT STATUS
156.Ex -std
157.Sh EXAMPLES
158Display the last 500 lines of the file
159.Ar foo :
160.Pp
161.Dl $ tail -n 500 foo
162.Pp
163Keep
164.Pa /var/log/messages
165open, displaying to the standard output anything appended to the file:
166.Pp
167.Dl $ tail -F /var/log/messages
168.Pp
169Read
170.Pa /var/log/messages
171from the beginning and then follow the file as usual:
172.Pp
173.Dl $ tail -F -n +1 /var/log/messages
174.Sh SEE ALSO
175.Xr cat 1 ,
176.Xr head 1 ,
177.Xr sed 1 ,
178.Xr expand_number 3
179.Sh STANDARDS
180The
181.Nm
182utility is expected to be a superset of the
183.St -p1003.2-92
184specification.
185In particular, the
186.Fl F ,
187.Fl b
188and
189.Fl r
190options are extensions to that standard.
191.Pp
192The historic command line syntax of
193.Nm
194is supported by this implementation.
195The only difference between this implementation and historic versions
196of
197.Nm ,
198once the command line syntax translation has been done, is that the
199.Fl b ,
200.Fl c
201and
202.Fl n
203options modify the
204.Fl r
205option, i.e.,
206.Dq Li "-r -c 4"
207displays the last 4 characters of the last line
208of the input, while the historic tail (using the historic syntax
209.Dq Li -4cr )
210would ignore the
211.Fl c
212option and display the last 4 lines of the input.
213.Sh HISTORY
214A
215.Nm
216command appeared in PWB UNIX.
217