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 are the commands for Linux to view logs in real time

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces Linux real-time view log command which, the text is very detailed, has a certain reference value, interested friends must read!

How to view the contents of log files in real-time in Linux? There are many utilities that can help users output the contents of files as they change or are constantly updated. A common command for displaying file contents in real-time in Linux is the tail command (effectively managing files).

1. tail command-real-time monitoring logs

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 of Apache logs

The second version of the command is actually a command itself: tailf. You don't need to use the-f switch because the command is built in with the-f argument.

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

Real-time Apache log monitoring

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

tail -F keeps track of new log files being created and starts tracking new files instead of old ones.

$ 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 want to view only the last two lines of the log file in real time, use-n in conjunction 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

Multitail Command-Monitor multiple log files in real time

Another interesting command to display log files in real time is the multitail command. The name of the 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 Red Hat-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 simultaneously, execute the command shown in the following example.

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

multipoint monitoring log

3. lnav command-Monitor 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 Debian and Red Hat-based Linux distributions 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 both log files simultaneously 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. less command-Displays real-time output of log files

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

As with the tail utility, Shift+F pressing less in an open file will start after the file ends. Alternatively, you can also start with fewer +F flags to enter the live viewing file.

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

Monitor logs using the less command

The above is Linux real-time view log command what all the content, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to 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

Wechat

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

12
Report