tail (Unix)

from Wikipedia, the free encyclopedia

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 tailis defined by the POSIX standard.

Working method

The behavior and syntax of tailmany 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 stdinand supplies its output stdout, error messages are stderroutput 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 NLANGLC_ALLLC_CTYPEtail

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 tailthe 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 tailas 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, tailthe 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

Individual evidence

  1. a b tail specification of the POSIX standard. Retrieved April 25, 2019 .
  2. The Open Group Base Specifications Issue 7, 2018 edition, 12.2 Utility Syntax Guidelines. Retrieved April 25, 2019 .