fbpx tail Command in Linux: View Last Lines & Monitor Logs | Certificação Linux

tail Command in Linux: View File Ends and Monitor Logs Live

📅 01/01/2019 ⏱ 2 min ✍️ Uira Ribeiro
Linuxcommands
tail Command in Linux: View File Ends and Monitor Logs Live
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

The tail command in Linux displays the last 10 lines of a file in the terminal. It also continuously reads a file with the "-f" option, widely used to check LOG files.

The tail command is the opposite of the head command and in English means tail.

The most common options are:

  • -n number: Specifies the number of ending lines that tail will display from a file;
  • -f: Shows the last ending lines of a file continuously while another process writes more lines. Very useful for viewing LOG files.

Examples:

Shows the last 50 lines of the messages file:

$ tail –n 50 /var/log/messages

Shows the last entries in the messages file continuously:

$ tail –f /var/log/messagens

Tail is undoubtedly a widely used command by programmers for LOG analysis, especially in WEB applications.

In this type of application, it is usually necessary to monitor more than one LOG file simultaneously, such as the Web server LOG and the PHP service log.

Multitail

To check more than one LOG file simultaneously, you can install the multitail tool.

It can be installed on CentOS, Red Hat and Fedora with the command:

$ sudo yum install multitail

On Debian and Ubuntu:

$ sudo apt install multitail

To run it, just provide the path of the files you want to check. Multitail already does the "-f" option automatically, showing the content of the files continuously.

$ multitail /var/log/nginx/access.log /var/log/php-fpm/www-error.log
Multitail Screen

Conclusion

The tail command is widely used for inspecting LOG files in Linux, especially with the "-f" option that keeps reading the LOG text file in the terminal.

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Like it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp