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 method of real-time monitoring log content in Linu system?

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

Share

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

The content of this article mainly focuses on what is the method of real-time monitoring log content in Linu system. The content of the article is clear and clear. It is very suitable for beginners to learn and is worth reading. Interested friends can follow the editor to read together. I hope you can get something through this article!

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.

1$ 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.

1$ 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.

1$ 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.

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

View the last two lines of the log

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.

123$ 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.

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

Multipoint monitoring log

3. 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.

123$ 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 both log files at the same time by issuing the command, as shown in the following example.

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

Lnav-Real-time log monitoring

4. Less command displays the real-time output of log files

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.

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

Use the less command to monitor logs

Thank you for your reading. I believe you have a certain understanding of "what is the method of real-time monitoring log content in Linu system". Go ahead and practice it. If you want to know more about it, you can follow the website! The editor will continue to bring you better articles!

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