Skip to main content

Module 3: Text Processing & Search

Lesson 25: tail Command

In this lesson, you'll learn how to use the tail command to display the last few lines of a file in Linux.

The tail command allows you to display the last ten lines of any text file. It also supports options for "n" number of lines and "n" number of characters.

tail Command Syntax

The basic syntax of the tail command is:

# tail [OPTIONS] [FILENAMES]

tail Command Options

Option Description
-n N Display the last N lines of the file
-c N Display the last N bytes (characters) of the file
-f Follow the file in real time, displaying new lines as they are added
-F Same as -f but keeps retrying if the file is inaccessible
-q Suppress the filename header when using multiple files
-v Always display the filename as a header

1. Display the Last 10 Lines of a File

By default, the tail command displays the last ten lines of a file. For example, the following command will print the last ten lines of a file called access.log.

# tail access.log
1390288226.042 0 172.16.18.71 TCP_DENIED/407 1771 GET http://download.newnext.me/spark.bin? - NONE/- text/html
1390288226.198 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html
1390288226.210 1182 172.16.20.44 TCP_MISS/200 70872 GET http://mahavat.gov.in/Mahavat/index.jsp pg DIRECT/61.16.223.197 text/html
1390288226.284 70 172.16.20.44 TCP_MISS/304 269 GET http://mahavat.gov.in/Mahavat/i/i-19.gif pg DIRECT/61.16.223.197 -
1390288226.362 570 172.16.176.139 TCP_MISS/200 694 GET http://p4-gayr4vyqxh7oa-3ekrqzjikvrczq44-if-v6exp3-v4.metric.gstatic.com/v6exp3/redir.html pg
1390288226.402 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html
1390288226.437 145 172.16.18.53 TCP_DENIED/407 1723 OPTIONS http://172.16.25.252/ - NONE/- text/html
1390288226.445 0 172.16.18.53 TCP_DENIED/407 1723 OPTIONS http://172.16.25.252/ - NONE/- text/html
1390288226.605 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html
1390288226.808 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html

2. Display the Last 10 Lines of Multiple Files

Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’