Blog

How to read logs in Linux

Linux stores its log files in the /var/log directory in text format.

tail command

The tail command is the most common solution for viewing a real-time log file. However, the command to view the file has two versions, as shown in the following examples. The tail command needs the -f argument to track the contents of a file.
sudo tail -f /var/log/apache2/access.logsudo tailf /var/log/apache2/access.log
To display, for example, only the last two lines of code, we will use the command
sudo tail -n2 -f /var/log/apache2/access.log

Multitail command

Multitail allows you to monitor and track multiple files in real time. Multitail also allows you to move back and forth in the monitored file.

Multitail installation

sudo apt install multitail
sudo yum install multitail
sudo dnf install multitail

Displaying logs using Multitail

sudo multitail first_file_patch second_file_patch
sudo multitail /var/log/apache2/access.log /var/log/apache2/error.log

lv command

lnav , like Multitail, allows you to view several files at the same time

lv installation

sudo apt install lnav
sudo yum install lnav
sudo dnf install lnav

Displaying logs using lv

sudo lnav first_file_patch second_file_patch
sudo lnav /var/log/apache2/access.log /var/log/apache2/error.log

Similar Posts