
lnav - A Smarter Way to View and Analyze Logs on Linux and Unix
- 4 minsIntroduction
As every system administrator or developer knows, logs are your best friend when things break. They reveal errors, warnings, and performance issues — but working with them using just cat, tail, less, or grep quickly becomes overwhelming.
When dozens of log files are rotating, compressed, or scattered across multiple directories, it’s hard to make sense of the noise. That’s where lnav (Logfile Navigator) comes in: a powerful terminal-based log viewer that doesn’t just show you logs, but actually helps you understand them.
1. Why Use lnav Instead of Traditional Tools?
Unlike plain-text viewers, lnav is log-aware. It recognizes timestamps, log levels, and structured formats, so you don’t need to write endless regex filters.
Key features include:
- Automatic log format detection (syslog, Apache/Nginx, JSON, and more).
- Merging multiple files into a single chronological view.
- Color highlighting of warnings, errors, and critical messages.
- Follow mode (like tail -f) that survives file rotations and renames.
- On-the-fly decompression of .gz logs.
- Jump between warnings and errors with a single keystroke.
- Regex search, filtering, and highlighting.
- Histograms and charts showing log activity over time.
- SQLite integration — query logs with SQL as if they were database tables.
- Remote log viewing over SSH/SFTP.
- Docker integration to explore container logs.
In short: lnav consolidates the functionality of tail, less, grep, and journalctl into one interactive tool.
2. Installing lnav
Installation depends on your platform:
#Debian/Ubuntu:
sudo apt install lnav
#RHEL/CentOS/Fedora/Rocky/Alma:
sudo dnf install lnav
#Arch Linux:
sudo pacman -S lnav
3. Basic Usage
The simplest way to start:
lnav /var/log/syslog
lnav /var/log/nginx/error.log /var/log/nginx/access.log
You can also pass a directory:
lnav /var/log/
Or use wildcards:
lnav /var/log/*.log
4. Integration with journalctl
On systemd-based Linux systems, you can pipe logs directly:
journalctl | lnav
journalctl -f | lnav
journalctl -u ssh.service | lnav
5. Navigating Logs
- Press e → jump to next error.
- Press Shift+E → previous error.
- Press w → next warning.
- Press Shift+W → previous warning.
- Press / → search with regex.
- Press q or CTRL+C → exit.
These shortcuts make sifting through massive log files dramatically faster.
6. Working with Remote Logs
You can pull logs directly over SSH/SFTP:
lnav user@host:/var/log/syslog
lnav admin@server:/var/log/nginx/*.log
No need to copy files locally first — lnav handles them seamlessly.
7. Using with Docker
You can explore container logs as well:
docker logs app | lnav
docker logs -f container_id | lnav
Or use the built-in docker:// syntax:
lnav docker://my-container/var/log/nginx/error.log
8. Turning Logs into SQL Tables
This is the killer feature: lnav automatically parses logs into structured fields and exposes them as SQLite virtual tables.
Example:
lnav /var/log/nginx/access.log
Then press ; to enter SQL mode:
SELECT remote_host, count(*)
FROM access_log
GROUP BY remote_host
ORDER BY count(*) DESC
LIMIT 5;
Now you’ve turned raw logs into a quick report of top visitors — without leaving the terminal.
9. Watching Command Output
You can also use lnav as a live viewer for any command:
lnav -e 'make -j8'
Instead of endless scrolling output, you get structured, colored log parsing.
10. Best Practices
- Use lnav for exploratory debugging when grep and tail aren’t enough.
- Combine journalctl + lnav for systemd environments.
- For long-running services, use SQL queries to quickly find trends.
- Bookmark the docs — advanced SQL functions unlock the real power.
Conclusion
lnav is much more than a pager for logs — it’s an interactive log analysis tool that gives developers and admins real insight into what’s happening under the hood. From color-coded error jumps to SQL-powered analytics, it turns messy text files into structured, searchable data.
If you’ve ever felt lost in /var/log/, give lnav a try. You’ll spend less time digging and more time understanding.
Thanks for reading!
—
Guneycan Sanli