#!/usr/bin/perl -w use strict; die "Usage: $0 file numlines\n" unless @ARGV == 2; my ($filename, $numlines) = @ARGV; # open or die first so that we don't stat a file we don't know exists open my $fh, "<", $filename or die "Couldn't open $filename: $!"; my $chunksize = 2 * 200 * $numlines; my $filesize = -s $fh; $chunksize = $filesize if $filesize < $chunksize; # why seek twice? seek $fh, -$chunksize, 2; my @tail = <$fh>; splice @tail, 0, @tail - $numlines; print @tail; __END__ $ perl -le'print "a"x500 for 1..10' > t.dat $ tailz t.dat 5 | wc -l 1