Introduction
This tutorial explores the tail
command in Linux, a utility designed to display the last lines of a text file. We will cover its basic usage and introduce various parameters for enhanced functionality.
This tutorial explores the tail
command in Linux, a utility designed to display the last lines of a text file. We will cover its basic usage and introduce various parameters for enhanced functionality.
The tail
command is used to view the end of a file, making it particularly useful for monitoring log files, tracking real-time changes, or simply inspecting the concluding lines of a document.
Let's start with a basic example. We have a file called example.txt
in the /home/labex/project
directory, and we want to display the last 10 lines of a file.
Input:
tail /home/labex/project/example.txt
Output:
Imagine you have a list of your favorite fruits:
1. Apple
2. Banana
3. Orange
4. Grape
5. Strawberry
Now, let's use the head command to peek at the last few lines of this list.
This command displays the last 10 lines of the specified file (example.txt
). Similar to the previous tutorials, this initial stage will focus solely on the basic usage of the tail
command.
The tail
command offers a variety of parameters to customize its behavior. We will introduce some of the most commonly used ones and provide usage examples in increasing order of complexity.
The tail
command supports various options to customize its behavior. Here are a few common options:
-n N
: Display the last N lines of the file.-c N
: Display the last N bytes of the file.The -n
option in the tail
command is used to specify the number of lines to display from the end of a file.
Input:
tail -n 3 /home/labex/project/example.txt
Output:
5. Strawberry
Now, let's use the tail command to peek at the last few lines of this list.
In this example, tail -n 3
displays the last three lines of the file.
The -c
option in the tail
command is used to specify the number of characters to display from the end of a file.
Input:
tail -c 71 /home/labex/project/example.txt
Output:
let's use the head command to peek at the last few lines of this list..
In this example, tail -c 50
displays the last 50 characters of the file.
In summary, the tail
command is a versatile tool for inspecting the end of a text file. Whether you need to view a specific number of lines, bytes, or follow a file in real-time, tail
provides an efficient solution for examining the concluding portion of a document.