FactorPad
Faster Learning Tutorials

Linux tail command summary with examples

tail allows you to print the last lines of a file.
  1. Purpose - Learn what tail is for and how to find help.
  2. Options - Review a few common options and examples.
  3. Examples - Walk through code examples with tail.
  4. A tip - Finish off with one more insight.
Paul Alan Davis, CFA, October 16, 2016
Updated: July 31, 2018
In this tutorial, 28 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Next

~/ home  / tech  / linux essentials  / tail command


The Linux tail command

Beginner

Learn to view the last lines of a file at the Linux command line.

Video Tutorial

Linux tail command summary with examples (3:53)

Videos can also be accessed from the YouTube Playlist.

Video Script

The Command and Why You Need It

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.

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.

Demonstration

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.

$ ls stuff video11.txt video19.txt video21.txt video24.txt video27.txt video05.txt video16.txt video20.txt video23.txt video26.txt $ tail video27.txt --help display this help and exit --version output version information and exit K may have a multiplier suffix: b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Full documentation at: <http://www.gnu.org/software/coreutils/head> or available locally via: info '(coreutils) head invocation'

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.

$ tail -n 7 video27.txt K may have a multiplier suffix: b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Full documentation at: <http://www.gnu.org/software/coreutils/head> or available locally via: info '(coreutils) head invocation'

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.

$ clear $ tail ../.bash_history whatis head more head less tail whoami cat man which man cat man whoami --help clear exit

Hmmm, interesting. ;)

A Final Tip

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.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

More good times can be had at the YouTube Channel, subscribe here.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the head command, hit Back.
  • To change gears and focus on finding help with commands using the apropos, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / tail command



 
 
Keywords:
linux tail command
tail linux
linux tail
tail command
unix tail
tail log file
print last lines of file
view log files
display last lines
man tail
tail command syntax
tail number
tail lines
linux tail examples
linux tail tutorial
linux tail command parameters