tail Command in Linux: View File Ends and Monitor Logs Live
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
That was just one piece. The course teaches the whole path — from your first command to exam day.
Multitail Screen