Tail command on Linux (final file reading) [Basic Guide]

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:

$ sudo 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

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.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

This website uses cookies.