Skip to content

Tail command on Linux (final file reading)

The tail command on 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 inverse of the head command.

The most common options are:

  • -n number: Specifies the number of final lines that the tail will show from a file;
  • -f: Shows the last final 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

Continuously shows the latest entries in the messages file:

$ tail —f /var/log/messages

The tail is undoubtedly the command widely used by programmers for LOG analysis, especially in WEB applications.

In this type of application, it is generally 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:

$ <a data-id="1082" data-type="post" href="https://www.linuxcertification.academy/sudo-command-on-linux-privilege-scale-basic-guide/">sudo</a> yum install multitail

On Debian and Ubuntu:

$ sudo apt install multitail

To execute it, simply provide the path of the files you want to scan. Multitail already makes 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
![](https://learnlinux.com.br/editor/files/multitail_pt.jpg)
Conclusion ----------

The tail command is widely used for inspecting LOG files on Linux, especially with the “-f” option that maintains the reading of the LOG text file in the terminal.