Quick Techniques to Pinpoint Errors in Massive Log Files Using Linux Commands
Learn how to efficiently locate error entries in huge log files by combining tail, head, grep, sed, and pagination commands, extracting specific line numbers, time ranges, occurrence counts, and highlighted matches with context for faster debugging.
Quickly locate errors in large logs
This guide shows practical Linux command‑line techniques for finding error information in massive log files such as catalina.out. It covers extracting line numbers, searching by time range, counting occurrences, highlighting matches, and paging through results.
Method 1 – Find line numbers with grep and view surrounding lines
First obtain the line number of the target keyword, then use tail and head to display nearby entries.
cat -n catalina.out | grep "keyword"
# example output shows line numbers like 13230539 cat -n catalina.out | tail -n +13230539 | head -n 10The tail -n +<line> option starts reading from the specified line, while head -n <count> limits the output to the desired number of lines.
Method 2 – Search within a specific time window
Use grep to verify the timestamps exist, then extract the range with sed.
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.outMethod 3 – Count occurrences of a specific string
grep '1175109632' catalina.out | wc -lThe command returns the total number of matching lines.
Method 4 – View the last N lines and filter a keyword
tail -n 20 catalina.out | grep 'INFO Takes:1'Method 5 – Highlight matches in the last N lines
tail -n 20 catalina.out | grep 'INFO Takes:1' --colorMethod 6 – Show matches with surrounding context
tail -n 20 catalina.out | grep 'INFO Takes:1' --color -A2The -A2 option prints two lines after each match.
Method 7 – Paginate results using more or less
tail -n 2000 catalina.out | grep 'INFO Takes:1' --color -A2 | more tail -n 2000 catalina.out | grep 'INFO Takes:1' --color -A2 | lessBoth utilities let you scroll through large outputs efficiently.
Navigation shortcuts for less
Ctrl+F – forward one screen
Ctrl+B – backward one screen
Ctrl+D – forward half screen
Ctrl+U – backward half screen
j – move down one line
k – move up one line
G – jump to the last line
g – jump to the first line
q or ZZ – exit
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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
