Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the command for Linux system to view logs in real time?

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you what is the command for real-time log viewing of the Linux system. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

The log is a very important file in the system, for the system administrator, the log is very important, the log constantly records something that happens in the system, so how to view the log in real time?

1. Tail command real-time monitoring log

As mentioned above, the tail command is the most common solution for displaying log files in real time. However, there are two versions of the command to display the file, as shown in the following example.

In the first example, the command tail requires the-f argument to track the contents of the file.

$sudo tail-f / ``var`` / log/apache2/access.log

Real-time monitoring Apache logs

The second version of the command is actually a command itself: tailf. You do not need to use the-f switch because the command is built in with the-f parameter.

$sudo tailf / ``var`` / log/apache2/access.log

Real-time Apache log monitoring

Typically, the logrotate utility rotates log files frequently on the Linux server. To view log files that rotate on a daily basis, you can use the tail-F command.

Tail-F tracks the new log file being created and starts tracking the new file instead of the old one.

$sudo tail-F / ``var`` / log/apache2/access.log however, by default, the tail command displays the last 10 lines of the file. For example, if you only want to view the last two lines of the log file in real time, use the file that combines the-n with the-f flag, as shown in the following example.

$sudo tail-N2-f / ``var`` / log/apache2/access.log

View the last two lines of the log

The 2.multitail command monitors multiple log files in real time. Another interesting command to display log files in real time is the multitail command. The name of this command means that the multitail utility can monitor and track multiple files in real time. Multitail also allows you to navigate back and forth through monitored files.

To install the mulitail utility on Debian-and RedHat-based systems, issue the following command.

$sudo apt install multitail [On Debian&Ubuntu] ``$sudo yum install multitail [On RedHat&CentOS] `$sudo dnf install multitail [On Fedora 22 + version] to display the output of both log files, execute the command shown in the following example.

$sudo multitail / ``var`` / log/apache2/access.log / ``var`` / log/apache2/error.log

Multipoint monitoring log

3.The lnav command monitors multiple log files in real time. Another interesting command, similar to the multitail command, is the lnav command. The Lnav utility can also view and track multiple files and display their contents in real time.

Install the lnav utility in the Debian and RedHat-based Linux distribution by issuing the following command.

$sudo apt install lnav [On Debian&Ubuntu] ``$sudo yum install lnav [On RedHat&CentOS] `$sudo dnf install lnav [On Fedora 22 + version] observe the contents of two log files at the same time by issuing the command, as shown in the following example.

$sudo lnav / ``var`` / log/apache2/access.log / ``var`` / log/apache2/error.log

Lnav-Real-time log monitoring

4.The less command displays the real-time output of the log file. Finally, if you type, you can use the less command to display the real-time output Shift+F of the file.

Like the tail utility, Shift+F pressing less in an open file starts after the file ends. Alternatively, you can start to enter the scene to view the files with fewer + F flags.

$sudo less + F / ``var`` / log/apache2/access.log

Use the less command to monitor logs

The above is the command for the Linux system to view the log in real time. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report