Mastering Less: Line Numbers, Pattern Jumps, and Line Chopping for Big Log Files
When you’re hunting down a bug in a 10‑GB log, Less can be more than a pager. Learn how to toggle line numbers, jump to patterns, and chop long lines to keep your view stable, with real commands, trade‑offs, and a practical example.
28 Apr 2026, 14:05 UTC

Why Less Matters for Huge Logs
When debugging a production system, you often end up scrolling through gigabytes of text. A simple pager that can jump straight to the problem and keep the screen tidy is worth its weight. Less offers three under‑used flags that make this possible: -N for line numbers, -p for pattern jumps, and -S for line chopping.
1. Turn on Line Numbers with -N
Without line numbers, you can’t refer to a specific line in a diff or when asking teammates for help. Running less -N logfile prints the line number in a narrow column on the left. It’s a one‑time flag that can be made permanent by adding -N to the LESS environment variable or an alias.
# Shell check
$ echo $LESS
# If empty, set it
$ export LESS='-N'
# Or create an alias for reproducibility
$ alias less='less -N'
**Check**: Open a file and verify that the first column contains numbers. If you see a header like "--More--" or the line numbers are missing, the flag didn’t apply.
**Risk**: In a terminal that is only 80 columns wide, the line numbers consume space that could otherwise show content. For very short outputs, you might prefer to leave them off.
2. Jump Directly to a Pattern with -p
Searching inside Less with / is useful, but when you know the exact string you’re after, -p can skip straight to it. For a log named app.log, the command below opens the file and lands on the first occurrence of "ERROR":
$ less -p 'ERROR' app.log
**Permissions**: No special privileges are required; you just need read access to the file.
**Check**: The cursor should sit on a line containing the pattern. If it jumps to the end of the file, the pattern isn’t present.
**Trade‑off**: If the pattern appears many times, you’ll still need to navigate manually. Use n and N to cycle forward and backward, or combine -p with -i for case‑insensitive matching.
3. Keep the Viewport Stable with -S
Logs often contain long stack traces or URLs that exceed the terminal width. The default Less behavior wraps these lines, shuffling the rest of the view and making navigation harder. -S chops the line at the viewport edge, leaving the rest hidden until you scroll horizontally.
$ less -S app.log
**Check**: Long lines should end with an ellipsis (…) or a visible cut marker, depending on your terminal’s rendering. If you scroll right with Ctrl‑ or Right‑Arrow, you can peek at the hidden part.
**Risk**: Important data beyond the cut point may be missed. If your log contains critical timestamps or identifiers that wrap, consider using -S only for non‑critical sections.
4. Combine Flags for a Powerful One‑liner
Putting it all together gives you a concise command that opens a log, numbers the lines, jumps to the first error, and keeps the view tidy:
$ less -N -p 'ERROR' -S app.log
**Actionable Tip**: Create a shell alias so you never have to remember the flags:
# Add to ~/.bashrc or ~/.zshrc
alias llog='less -N -S -p'
# Usage
$ llog 'ERROR' app.log
This alias passes the pattern as the first argument and the file as the second.
5. When to Use and When to Avoid
- Use
-Nwhen collaborating or writing tickets. It gives a clear reference point. - Use
-pfor quick hunts of known error strings. It saves time compared to scrolling. - Use
-Swhen you want a stable vertical scroll bar. Don’t use it if you need to see the full line for analysis. - For very large files, consider piping through
grepfirst to reduce size, e.g.,grep -i error app.log | less -N -S.
6. Quick Verification Checklist
- Run
less -N -p 'ERROR' -S app.logand confirm the cursor lands on a line with "ERROR". - Check that the leftmost column shows numbers.
- Verify that a long line is truncated at the right edge.
- Use q to exit and confirm no state was changed in the log file.
Conclusion
Less isn’t just a passive viewer; with the right flags you can turn it into a focused log‑analysis tool. Line numbering, pattern jumps, and line chopping give you precision, speed, and stability when dealing with massive logs. Add a simple alias to your shell, and you’ll spend less time scrolling and more time fixing bugs.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.