Operations 11 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Quick Techniques to Pinpoint Errors in Massive Log Files Using Linux Commands

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 10

The 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.out

Method 3 – Count occurrences of a specific string

grep '1175109632' catalina.out | wc -l

The 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' --color

Method 6 – Show matches with surrounding context

tail -n 20 catalina.out | grep 'INFO Takes:1' --color -A2

The -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 | less

Both 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

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxcommand-linelog analysisGreptailsed
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.