Master Quick Log Analysis: Powerful Linux Commands to Pinpoint Errors Fast
This guide shows how to efficiently locate errors in massive server logs using Linux commands like tail, cat, grep, sed, and navigation shortcuts, providing step‑by‑step techniques for dynamic viewing, time‑range searches, keyword filtering, and paginated inspection.
Today we discuss how to quickly locate errors in massive log files.
Fast error pinpointing in large logs
Dynamic log viewing tail -f catalina.out Open log file from the beginning cat catalina.out Redirect a new log to a file for inspection >nanjiangtest.txt Example of grepping a specific line number and saving
# cat -n catalina.out | grep 717892466 >nanjiangtest.txtSimple tail/head commands
# tail -n number catalina.out # show last number lines
# tail -n +number catalina.out # show from line number onward
# head -n number catalina.out # show first number lines
# head -n -number catalina.out # show all but last number linesMethod 1: Find line numbers by keyword
Use grep to get few lines, then locate surrounding logs. # cat -n test.log | grep "keyword" Combine tail and head to view context
# cat -n catalina.out | tail -n +13230539 | head -n 10Method 2: Search logs within a time range
grep '11:07 18:29:20' catalina.out
grep '11:07 18:31:11' catalina.out
sed -n '/11:07 18:29:20/,/11:07 18:31:11/p' catalina.out
sed -n '/11:07 18:29:/,/11:07 18:31:/p' catalina.outMethod 3: Count occurrences of a specific string
grep '1175109632' catalina.out | wc -lMethod 4: Get last number lines and filter keyword
# tail -n 20 catalina.out | grep 'INFO Takes:1'Method 5: Same as above with colored output
# tail -n 20 catalina.out | grep 'INFO Takes:1' --colorMethod 6: Show two lines of context around matches
# tail -n 20 catalina.out | grep 'INFO Takes:1' --color -a2Method 7: Paginated view using more/less
# tail -n 2000 catalina.out | grep 'INFO Takes:1' --color -a2 | more
# tail -n 2000 catalina.out | grep 'INFO Takes:1' --color -a2 | lessAdditional navigation shortcuts
Full-screen navigation
ctrl + F– move forward one screen ctrl + B – move backward one screen ctrl + D – move forward half screen ctrl + U – move backward half screen
Single-line navigation
j– move forward one line k – move backward one line
Other navigation
G– go to last line g – go to first line q / ZZ – quit less
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
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.
