tail (Unix)
tail
( /usr/bin/tail
), (English "tail", "end") is one of the many text filters in UNIX that comply with the POSIX standard - and these similar operating systems and is used to output the last lines of a file. Its counterpart is that which displays the first few lines of a file.
head
The scope of functions and the behavior tail
is defined by the POSIX standard.
Working method
The behavior and syntax of tail
many other command line programs are the same , in particular reference is made in the specification to the IEEE Std 1003.1-2017 standard . It expects either a file name or an input data stream stdin
and supplies its output stdout
, error messages are stderr
output on. Output can be rerouted using conventional means ( redirection , pipeline ).
tail [Optionen] [<file>]
How much of a file is output can be specified either in bytes ( where N is the number of bytes) or in lines ( where N is the number of lines). Caution : since the internationalization variables ( , , etc.) the function of influence considerably the number of characters does not equal the number of bytes (for example in Unicode files). Modifiers can also be used to determine whether the count is relative from the beginning of the file or from the end (the default):
-c N
-n N
LANG
LC_ALL
LC_CTYPE
tail
tail -c +100 /path/to/input # gibt alles ab dem 100. Byte des Inputs aus tail -c -100 /path/to/input # beide Versionen geben die letzten 100 Byte des Inputs aus tail -c 100 /path/to/input tail -n +100 /path/to/input # gibt alles ab der 100. Zeile des Inputs aus tail -n -100 /path/to/input # beide Versionen geben die letzten 100 Zeilen des Inputs aus tail -n 100 /path/to/input
Outputs tail
the last 10 lines of a file as default .
Obsolete syntax variants
Most implementations (e.g. AIX , HP-UX ) also understand a syntax - no longer recommended for use - that works without the option -n
:
tail -20 /path/to/input # die letzten 20 Zeilen des Inputs tail -50c /path/to/input # die letzten 50 Bytes des Inputs
This syntax does not correspond to the POSIX standard and should therefore be avoided. It cannot be assumed that this syntax will still be supported on any system or any future version of the same.
Change tracking
With the -f
(follow) switch , the output is continuously updated until the signal is sent to the program SIGINT
(e.g. with the key combination Strg+ C). This function makes it suitable tail
as a live monitor for constantly changing files (e.g. logs ).
The following example shows the last 15 lines of the log of a HACMP cluster ( /usr/es/adm/cluster.log
) and continuously adds new entries:
tail -fn 15 /usr/es/adm/cluster.log
Nonstandard variants
When tracking changes, tail
the open file is followed by means of a filehandle , which is why naive log file rotation by renaming and creating a new file prevents further tracking. Some implementations take this into account by introducing an additional option ( -F
) that identifies the file to be tracked solely by its file name.
Web links
-
tail
: copy the last part of a file - Open Group Base Specification -
tail(1)
: display the last part of a file - OpenBSD General Commands Manual -
tail(1)
: Print the last part of files - Debian GNU / Linux Executables or Shell Commands man page
Individual evidence
- ↑ a b tail specification of the POSIX standard. Retrieved April 25, 2019 .
- ↑ The Open Group Base Specifications Issue 7, 2018 edition, 12.2 Utility Syntax Guidelines. Retrieved April 25, 2019 .