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