Master Real-Time Log Monitoring on Linux with Tail, Multitail, Lnav & Less
This guide explains how to monitor Linux log files in real time using commands such as tail (with -f, -F, and -n options), tailf, multitail, lnav, and less, including installation steps and example usages for Apache logs.
On Linux, you can view log files in real time using several tools; the most common is the
tailcommand.
1. tail Command – Monitor Logs in Real Time
The
tailcommand is the most common way to view log files as they grow. Use the
-foption to follow a file:
<code>$ sudo tail -f /var/log/apache2/access.log</code>Alternatively, the
tailfcommand has
-fbuilt‑in, so you can run:
<code>$ sudo tailf /var/log/apache2/access.log</code>When logs are rotated, use
-Fto follow the name even if the underlying file descriptor changes:
<code>$ sudo tail -F /var/log/apache2/access.log</code>To display only the last two lines while following, combine
-nand
-f:
<code>$ sudo tail -n2 -f /var/log/apache2/access.log</code>2. Multitail Command – Monitor Multiple Log Files in Real Time
Install Multitail on Debian/Ubuntu, RedHat/CentOS, or Fedora:
<code>$ sudo apt install multitail [On Debian & Ubuntu]</code> <code>$ sudo yum install multitail [On RedHat & CentOS]</code> <code>$ sudo dnf install multitail [On Fedora 22+]</code>Example to view two logs simultaneously:
<code>$ sudo multitail /var/log/apache2/access.log /var/log/apache2/error.log</code>3. lnav Command – Monitor Multiple Log Files in Real Time
Install lnav similarly:
<code>$ sudo apt install lnav [On Debian & Ubuntu]</code> <code>$ sudo yum install lnav [On RedHat & CentOS]</code> <code>$ sudo dnf install lnav [On Fedora 22+]</code>View two logs with lnav:
<code>$ sudo lnav /var/log/apache2/access.log /var/log/apache2/error.log</code>4. less Command – Display Real‑Time Output of Log Files
Open a log with
lessand press
Shift+Fto follow the end of the file, similar to
tail -f. You can also start less with the
+Foption:
<code>sudo less +F /var/log/apache2/access.log</code>Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.