FactorPad
Build a Better Process

Linux tail Command Summary with Examples

Linux 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.
face pic by Paul Alan Davis, CFA
Updated: February 23, 2021
In this tutorial on Linux tail, 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 Tip Next

/ factorpad.com / tech / linux-essentials / tail-command.html


An ad-free and cookie-free website.


The Linux tail command

Beginner

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

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux tail Command Summary with Examples (3:53)

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.

Common Linux tail Options
-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.

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 and follow @factorpad on Twitter for new content notifications.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / tail-command.html


linux tail command
tail linux
linux tail examples
tail command
unix tail
tail log file
print last bytes
view log files
display last lines
man tail
tail command syntax
tail command summary
tail command options
linux tail tutorial
tail number
tail lines
linux tail examples

A newly-updated free resource. Connect and refer a friend today.