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:
Continuously shows the latest entries in the messages file:
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:
On Debian and Ubuntu:
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 screen |
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.