How to view and control log files on CentOS 8

All Linux systems create and store information about servers, boot processes, kernel, and applications in log files, which can be useful for troubleshooting as they contain logs of system activity. Log files are stored in / var / log directory and its subdirectory. In this tutorial, we will learn how to view and track log files in CentOS8 in various ways. So let’s get started.

View log files with tail command

This is the most commonly used command for viewing logs. To use this command –F used to track the contents of a file, open a terminal and enter the following command:

# sudo tail –f /var/log/apache2/access.log

How to view and control log files on CentOS 8

Because the log files are apparently changed. If you want to display a limited number of lines then use –N and the number of lines you want to display as shown below.

# sudo tail –n5 –f /var/log/apache2/access.log

How to view and control log files on CentOS 8

This command will only display the last five lines of the log file as shown below.

How to view and control log files on CentOS 8

Fewer teams

To view the file output in real time using –F with Less as shown below.

# sudo less –f /var/log/httpd/access_log

How to view and control log files on CentOS 8

How to view and control log files on CentOS 8

Using Multitail Command – View Multiple Log Files

If you want to display multiple log files at the same time use multipurpose command. The name itself implies that it is used to view and monitor multiple log files. To do this, we need to install the package first. Use the following command to install the package on CentOS8.

# sudo dnf install –y multitail

How to view and control log files on CentOS 8

After the installation is complete, it’s time to display two log files at the same time. To do this, use the following command.

# sudo multitail /var/log/httpd/access_log /var/log/httpd/error_log

How to view and control log files on CentOS 8

How to view and control log files on CentOS 8

Conclusion

In this tutorial, we learned how to view log files in different ways, we also saw how to view multiple log files at the same time using a multi-user command, how to display a limited number of lines.

How to view and control log files on CentOS 8

Sidebar