Reading Logs with less, more, and tail - Mastering Pager Commands
Don't Fear Logs - Just Start Reading Them
less command is for! Instead of dumping everything with cat, you can scroll through the file page by page.Log files are long. Opening them with cat floods your screen and scrolls past in seconds.
That's where pager commands come in. Learn less, more, and tail, and no log file will intimidate you again.
What You'll Learn
- How to read logs page by page and search inside them with
less - What
moredoes and when to use it instead ofless - How to view just the newest entries of a file with
tail - How to monitor logs in real time with
tail -f - A practical workflow for investigating error logs
less Basics - The King of Pagers
Conclusion:
lessscrolls page by page with search; it is the pager to reach for.
more already existed, so they named this more powerful one less as a joke.Opening a file with less
less /var/log/syslog
Nov 1 10:00:01 myserver systemd[1]: Started Daily apt download activities. Nov 1 10:00:23 myserver kernel: [12345.678] eth0: renamed from veth1234 Nov 1 10:00:30 myserver sshd[1234]: Accepted publickey for user from 192.168.1.1 ...
Once the file is open, use keyboard shortcuts to navigate.
less Navigation Keys
| Key | Action |
|---|---|
Space / f |
Next page |
b |
Previous page |
↓ / j |
One line down |
↑ / k |
One line up |
G |
Jump to last line |
g |
Jump to first line |
q |
Quit |
/keyword |
Search forward |
?keyword |
Search backward |
n |
Next search result |
N |
Previous search result |
The 3 keys to memorize first
Space: next pageq: quit/error: search for the word "error"
Searching Inside less
/ and type a keyword to search! Hit Enter to jump to the first match.Open a file with less, then type /error and press Enter.
It jumps to the first line containing "error". Press n for the next match, N for the previous one.
less highlights all search matches, making it easy to spot errors in a long log file.
more Basics - The Simple Pager
Conclusion:
moreonly moves forward with Space and cannot scroll back to past pages.
more similar to less?more /var/log/syslog
| Key | Action |
|---|---|
Space |
Next page |
Enter |
One line forward |
q |
Quit |
more cannot scroll backward. If you need to re-read earlier content, use less instead.
less vs. more - When to Use Which
Conclusion: Use
lessby default;morehelps on minimal systems withoutless.
less and forget about more?more is useful when less isn't installed on a minimal system. When in doubt, less is the right choice.| Feature | less |
more |
|---|---|---|
| Scroll backward | Yes | No |
| Search | Yes (with highlighting) | Basic or none |
| Pipe support | Yes | Yes |
| Default availability | Most systems | Nearly all systems |
Bottom line: When in doubt, use less.
tail Basics - Viewing the End of a File
Conclusion:
tailshows the end of a file, the last 10 lines by default,-nto set more.
tail command shows just the tail end of the file — the newest entries. By default, it shows the last 10 lines.tail /var/log/syslog
Nov 1 11:59:43 myserver systemd[1]: Starting Session 42 of User user. Nov 1 11:59:43 myserver systemd-logind[456]: New session 42 of user user. Nov 1 11:59:44 myserver sshd[5678]: session opened for user user by (uid=0) Nov 1 11:59:58 myserver systemd[1]: session-42.scope: Deactivated successfully.
Specifying the number of lines
tail -n 50 /var/log/syslog
The -n 50 flag shows the last 50 lines. You can also write it as -50:
tail -50 /var/log/syslog
The head command shows the beginning of a file. Learn tail and head together as a pair.
tail -f for Real-Time Monitoring
Conclusion:
tail -ffollows new lines as they are appended; stop it withCtrl+C.
tail -f! The -f stands for "follow" — it watches the file and prints each new line as it's appended.tail -f /var/log/nginx/access.log
192.168.1.1 - - [01/Jun/2026:12:00:01 +0900] "GET / HTTP/1.1" 200 1234 192.168.1.2 - - [01/Jun/2026:12:00:05 +0900] "GET /api/users HTTP/1.1" 200 5678 192.168.1.1 - - [01/Jun/2026:12:00:07 +0900] "POST /api/login HTTP/1.1" 200 89
Press Ctrl+C to stop.
tail -f keeps running until you stop it. Always press Ctrl+C when you're done monitoring.
Monitoring Multiple Files Simultaneously
tail -f /var/log/nginx/access.log /var/log/nginx/error.log
When watching multiple files, tail -f labels each new line with the filename it came from:
==> /var/log/nginx/access.log <== 192.168.1.3 - - [01/Jun/2026:12:01:00 +0900] "GET /image.png HTTP/1.1" 200 9876 ==> /var/log/nginx/error.log <== 2026/06/01 12:01:01 [error] 1234#0: *5 No such file or directory
Practical Log Investigation Workflow
Conclusion: Use
tail -n, thenlessto search, thentail -fto follow in real time.
tail -n 100 to see recent activity, then switch to less to investigate more closely.Step 1 - Check the most recent logs
tail -n 100 /var/log/syslog
Step 2 - Use less to search for errors
less /var/log/syslog
Inside less, type /error or /failed to search.
Step 3 - Watch logs in real time while reproducing the problem
tail -f /var/log/syslog
Combine with grep to filter noise
tail -f /var/log/syslog | grep -i error
This shows only lines containing "error" (case-insensitive) as they appear in real time.