4.9 C
Amsterdam
Saturday, December 5, 2020

The Linux tail command

Must read

How To Install Docker Swarm On Ubuntu 20.04

In this tutorial, you'll learn that how to Install Docker Swarm on Ubuntu 20.04. Docker Swarm is most popular tool that can be used...

How To Install Keeweb Password Manager On Ubuntu 20.04

Today we are going to learn that how to install KeeWeb Passwrod Manager On Ubuntu 20.04. KeeWeb Password Manager provides the best and easy...

How to change the MAC address in Windows 10

Hello! How are you? Today we will see how to change the MAC address on a computer with Windows 10. In fact, it is...

How To Configure Slave BIND DNS Server On Ubuntu 20.04

In our previous guide we covered the setup of Master(Primary) DNS Server. Here we'll learn that how to configure slave bind dns server on...
angeloma
angeloma
Senior Writer and partner

Hey, buddy. This time we will explain in detail the Linux tail command. Quite used by many sysadmin.

One of the most feared tools for newcomers is the Linux terminal. However, its use is decreasing every day thanks to the incredible improvements that the system has received. But in the administration of servers, there are no graphical interfaces to manage the system, for security reasons. So it’s up to you to familiarize yourself with the console and the commands.

And if we talk about commands there are many, but many syadmins use some more than the novice users. Tail is one of them and today we will help you to use it and tell you what it is used for.

The Tail command

Tail is a command to show the last lines of a text file. It is quite useful for exploring log files that generate services on Linux. Also, it is used to monitor changes that may have happened to this file.

:~$ tail [OPTION]… [FILE]…

Of course, this syntax is the basic form of usage. The behavior of the command is modifiable thanks to the options it has. To see them, use this command:

:~$ tail --help
1.- The tail command help
1.- The tail command help

However, I will explain with some examples of how easy and useful it is to use the Tail command.

Using the Linux tail command – examples

First, I created a text file containing several random names for this example. It is called example.txt and has the following content:

2.- Example file
2.- Example file

Now let’s get started.

To display the last 10 lines of the file, just use the following command:

:~$ tail example.txt
tom
david
joseph
clancy
richard
robert
henry
harry
paul
3.- Using the Linux tail command
3.- Using the Linux tail command

This is the most basic use of the command.

However, it is possible to change this behavior. For example, we can indicate how many lines to show. If we want to show the last 3 lines, just use it:

:~$ tail -n 3 example.txt
harry
paul
4.- using the command with options
4.- using the command with options

Simply replace the 3 with the number you want to display. Remember we’re always talking about the last few lines of the file.

On the other hand, we can show the lines that are after a specific line. For example, to show the lines after the 7th line:

:~$ tail +7 example.txt
clancy
richard
robert
henry
harry
paul
5.- The tail command
5.- The tail command

It’s super useful this option.

However, sysadmin uses this command to monitor log files. And it is possible to do it in real-time using the -f option. That is, the last lines of the file are displayed, but as it is modified, the output will be updated:

:~$ tail -f example.txt
6.- Monitoring files with tail
6.- Monitoring files with tail

Tail will monitor the file constantly, so press CTRL + C to exit.

Finally, you can display the command version as follows:

:~$ tail --version
tail (GNU coreutils) 8.28
 Copyright (C) 2017 Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html.
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.
 Written by Paul Rubin, David MacKenzie, Ian Lance Taylor,
 and Jim Meyering.

And that is it.

Conclusion

The Tail command is a very useful terminal command. Widely used by many sysadmin for daily work it is also used for all those who wish to quickly view the contents of a file. Thanks to the examples, shown, you can see the potential of it and take advantage of it.

Please share this post and join our Telegram channel.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

-

Latest article

How To Install Docker Swarm On Ubuntu 20.04

In this tutorial, you'll learn that how to Install Docker Swarm on Ubuntu 20.04. Docker Swarm is most popular tool that can be used...

How To Install Keeweb Password Manager On Ubuntu 20.04

Today we are going to learn that how to install KeeWeb Passwrod Manager On Ubuntu 20.04. KeeWeb Password Manager provides the best and easy...

How to change the MAC address in Windows 10

Hello! How are you? Today we will see how to change the MAC address on a computer with Windows 10. In fact, it is...

How To Configure Slave BIND DNS Server On Ubuntu 20.04

In our previous guide we covered the setup of Master(Primary) DNS Server. Here we'll learn that how to configure slave bind dns server on...

Install Fossil on Linux – An alternative to Git

Hello, friends. In this post, we will talk about a serious alternative to Git. In a few words, we'll show you how to install...
x