tail

Output the last part of files, print the last part (10 lines by default) of each FILE;
tail reads from standard input if no files are given or when given a FILE of `-'.

Syntax
      tail [options]... [file]...

      tail -Number [options]... [file]...

      tail +Number [options]... [file]...

Options

-COUNT
+COUNT
     This option is only recognized if it is specified first.  COUNT is
     a decimal number optionally followed by a size letter (`b', `k',
     `m') as in `-c', or `l' to mean count by lines, or other option
     letters (`cfqv').

-c BYTES
--bytes=BYTES
     Output the last BYTES bytes, instead of final lines.  Appending
     `b' multiplies BYTES by 512, `k' by 1024, and `m' by 1048576.

-f
--follow[=HOW]
     Loop forever trying to read more characters at the end of the file,
     presumably because the file is growing.  This option is ignored
     when reading from a pipe.  If more than one file is given, `tail'
     prints a header whenever it gets output from a different file, to
     indicate which file that output is from.

     There are two ways to specify how you'd like to track files with
     this option, but that difference is noticeable only when a
     followed file is removed or renamed.  If you'd like to continue to
     track the end of a growing file even after it has been unlinked,
     use `--follow=descriptor'.  This is the default behavior, but it
     is not useful if you're tracking a log file that may be rotated
     (removed or renamed, then reopened).  In that case, use
     `--follow=name' to track the named file by reopening it
     periodically to see if it has been removed and recreated by some
     other program.

     No matter which method you use, if the tracked file is determined
     to have shrunk, `tail' prints a message saying the file has been
     truncated and resumes tracking the end of the file from the
     newly-determined endpoint.

     When a file is removed, `tail''s behavior depends on whether it is
     following the name or the descriptor.  When following by name,
     tail can detect that a file has been removed and gives a message
     to that effect, and if `--retry' has been specified it will
     continue checking periodically to see if the file reappears.  When
     following a descriptor, tail does not detect that the file has
     been unlinked or renamed and issues no message;  even though the
     file may no longer be accessible via its original name, it may
     still be growing.

     The option values `descriptor' and `name' may be specified only
     with the long form of the option, not with `-f'.

--retry
     This option is meaningful only when following by name.  Without
     this option, when tail encounters a file that doesn't exist or is
     otherwise inaccessible, it reports that fact and never checks it
     again.

--sleep-interval=N
     Change the number of seconds to wait between iterations (the
     default is 1).  During one iteration, every specified file is
     checked to see if it has changed size.

--pid=PID
     When following by name or by descriptor, you may specify the
     process ID, PID, of the sole writer of all FILE arguments.  Then,
     shortly after that process terminates, tail will also terminate.
     This will work properly only if the writer and the tailing process
     are running on the same machine.  For example, to save the output
     of a build in a file and to watch the file grow, if you invoke
     `make' and `tail' like this then the tail process will stop when
     your build completes.  Without this option, you would have had to
     kill the `tail -f' process yourself.
          $ make >& makerr & tail --pid=$! -f makerr
     If you specify a PID that is not in use or that does not correspond
     to the process that is writing to the tailed files, then `tail'
     may terminate long before any FILEs stop growing or it may not
     terminate until long after the real writer has terminated.

--max-consecutive-size-changes=N
     This option is meaningful only when following by name.  Use it to
     control how long `tail' follows the descriptor of a file that
     continues growing at a rapid pace even after it is deleted or
     renamed.  After detecting N consecutive size changes for a file,
     `open'/`fstat' the file to determine if that file name is still
     associated with the same device/inode-number pair as before.  See
     the output of `tail --help' for the default value.

--max-unchanged-stats=N
     When tailing a file by name, if there have been this many
     consecutive iterations for which the size has remained the same,
     then `open'/`fstat' the file to determine if that file name is
     still associated with the same device/inode-number pair as before.
     When following a log file that is rotated this is approximately the
     number of seconds between when tail prints the last pre-rotation
     lines and when it prints the lines that have accumulated in the
     new log file.  See the output of `tail --help' for the default
     value.  This option is meaningful only when following by name.

-n N
--lines=N
     Output the last N lines.

-q
-quiet
--silent
     Never print file name headers.

-v
--verbose
     Always print file name headers.

If more than one FILE is specified, `tail' prints a one-line header consisting of ==> FILE NAME <== before the output for each FILE.

GNU `tail' can output any amount of data (some other versions of `tail' cannot). It also has no `-r' option (print in reverse), since reversing a file is really a different job from printing the end of a file; BSD `tail' (which is the one with `-r') can only reverse files that are at most as large as its buffer, which is typically 32k. A more reliable and versatile way to reverse files is the GNU `tac' command.

`tail' accepts two option formats: the new one, in which numbers are arguments to the options (`-n 1'), and the old one, in which the number precedes any option letters (`-1' or `+1'). If any option-argument is a number N starting with a `+', `tail' begins printing with the Nth item from the start of each file, instead of from the end.

Examples

Extract the last 85 lines from a file:

tail -85 file,txt

Extract lines 40-50 from a file, first using head to get the first 50 lines then tail to get the last 10:

head -50 file.txt | tail -10

“Money will buy a pretty good dog, but it won't buy the wag of his tail” ~ Henry Wheeler Shaw

Related:

csplit - Split a file into context-determined pieces
cut - Divide a file into several parts
fmt - Reformat paragraph text
head - Output the first part of file(s)
join - Join lines on a common field
paste - Merge lines of files
split - Split a file into fixed-size pieces
Equivalent Windows command: Get-Content -wait


© Copyright SS64.com 1999-2014
Some rights reserved