On Unix-like operating systems, the tail command reads a file, and outputs the last part of it (the “tail”).

The tail command can also monitor data streams and open files, displaying new information as it is written. For example, it’s a useful way to monitor the newest events in a system log in real time.

This page covers the GNU/Linux version of tail.

Description

By default, tail prints the last 10 lines of each file to standard output. If you specify more than one file, each set of output is prefixed with a header showing the file name.

  • Description
  • Syntax
  • Examples
  • Related commands
  • Linux commands help

If no file is specified, or if file is a dash ("-"), tail reads from standard input.

Syntax

tail [{-c |–bytes=}num] [-f] [–follow[={name|descriptor}]] [-F] [{-n |–lines=}num] [–max-unchanged-stats[=num]] [–pid=pid] [{-p|–quiet|–silent}] [–retry] [{-s |–sleep-interval=}num] [{-v|–verbose}] [file …]

tail –help

tail –version

Options

Examples

tail myfile.txt

Outputs the last 10 lines of the file myfile.txt.

tail -n 100 myfile.txt

Outputs the last 100 lines of the file myfile.txt.

tail -f myfile.txt

Outputs the last 10 lines of myfile.txt, and monitors myfile.txt for updates; tail then continues to output any new lines that are added to myfile.txt.

tail -f access.log | grep 24.10.160.10

This is a useful example of using tail and grep to selectively monitor a log file in real time.

The tail command follows the file forever. To stop it, press Ctrl+C.

In this command, tail monitors the file access.log. It pipes access.log’s final ten lines, and any new lines added, to the grep utility. grep reads the output from tail, and outputs only those lines which contain the IP address 24.10.160.10.

cat — Output the contents of a file.head — Display the first lines of a file.more — Display text one screen at a time.pg — Browse page by page through text files.