/ factorpad.com / tech / linux-essentials / tail-command.html
An ad-free and cookie-free website.
Beginner
Learn to view the last lines of a file at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux tail Command Summary with Examples (3:53)
Our twenty-eighth word, or command to memorize is tail
from our category
Text.
tail
allows you to print the last
lines of a file.
-options | description |
---|---|
--help |
Print help screen |
-n , --lines |
Print the last number of lines specified |
-c , --bytes |
Print the last number of bytes specified |
Recall from the previous video we talked about
head
, now we'll see that
the tail
command comes with a few
additional features.
Before we start, it helps to think of commands as mini programs and
most follow this structure:
command -option(s) argument(s)
.
The tail
command has
12 options, where head
had 6 and the argument is the file you'd like to
review.
Like most commands, help is available with double-dash
--help
.
The default is to print the last 10 lines, and the
-n
option allows you to view more or
less than 10. And just like with head
,
for bytes use -c
and not dash-b, as
you may think.
So why is tail
an important command?
Well, if you think about it, log files record system activity, and
tail
is a way to monitor the most
recent entries.
And now you know how to do that.
Okay, the best way to embed this in your memory is by typing in your own terminal window.
Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.
Here we go, let's look at the last 10 lines, the default, of the file
from the previous video, video27.txt
which was the help screen on the command
head
.
See how it prints right to the screen? Pretty easy huh?
Second, let's say we want to just look at this help information, so
let's do that on a tail
and the last 7
lines using -n 7
the file
video27.txt
.
And we're all set.
And last, for the interesting stuff, let's act like a system
administrator and monitor a user's file. The
tail
of this one, called
.bash_history
, shows my last 10
entries.
Hmmm, interesting. ;)
Okay now you know how to use tail
.
And you know the syntax for commands, options and arguments.
One last tip about the tail
command.
Well, when you review the help page for
tail
, read the
-s
, or sleep, option as it automates
the review of log files, which is a good security precaution.
Okay, thanks for visiting today. I hope this was a helpful
introduction to the tail
command.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
More good times can be had at the YouTube Channel, subscribe and follow @factorpad on Twitter for new content notifications.
head
command,
hit Back.apropos
, click Next./ factorpad.com / tech / linux-essentials / tail-command.html
A newly-updated free resource. Connect and refer a friend today.