tail Command Reference Guide for Unix / Linux Systems

The tail Command

   

Introduction

The tail command shows (by default) the last ten lines of a file. If no file is specified, tail will show the last ten lines of standard input (STDIN). The tail command is very useful when monitoring output files. If you're monitoring a weblog, you can have tail dynamically update the screen with any data that is appended to the log file.

Format:
tail <options> <input>

Quick Links!

Common Uses
Specify Number of Lines to Output
Observe data as it gets appended to a file.

Example

General usage: Here we have tail return the last ten lines of an rsync log.
-bash-3.00$ tail rsync.out 

csv/may2007/YUL20070425.csv
csv/may2007/YUL20070426.csv
csv/may2007/YUL20070427.csv
csv/may2007/YUL20070428.csv
csv/may2007/YUL20070429.csv
csv/may2007/YUL20070430.csv
csv/may2007/YUL20070431.csv

sent 37575 bytes  received 6404 bytes  29319.33 bytes/sec
total size is 21403082  speedup is 486.67

Common Uses

Specify number of lines to output

Here we use the line # option to specify how many lines we want to output from the end of our file/input. Programmers often want to be able to grab the last line of a certain file.
tail -4 shop.pl

   $CartNumber =~ s/\W*//g;
   $CartNumber =~ s/[A-Za-z]*//g;
   return $CartNumber;
}
Observe data as it gets appended to a file

One of my favorite unix commands is tail -f, because it turned my computer into a geeky observation station. Using the -f option allows you to sit and watch a text/log/any file on your system and as soon as data is appended to the end of it, bam! it appears on the screen. Turn that old pentium 2 into a web server monitor with tail -f