Operations 11 min read

Quick Techniques to Pinpoint Errors in Massive Log Files

Learn how to efficiently navigate, filter, and extract specific entries from large log files using tail, head, grep, sed, and pagination commands, with practical examples for locating error lines and time ranges.

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

Dynamic Log Viewing

Use tail -f catalina.out to follow a log file in real time.

Open Log from Start

Display the entire file with cat catalina.out or redirect output to a new file for further analysis:

# cat -n catalina.out | grep 717892466 > nanjiangtest.txt

Basic tail/head Commands

tail -n number catalina.out

– show the last number lines. tail -n +number catalina.out – display from line number onward. head -n number catalina.out – show the first number lines. head -n -number catalina.out – show all but the last number lines.

Method 1: Find Line Numbers by Keyword

First obtain the line number containing a keyword, then extract surrounding lines:

# cat -n catalina.out | grep "keyword"
# cat -n catalina.out | tail -n +13230539 | head -n 10

Method 2: Search Within a Time Range

Use grep to verify timestamps, then extract the range with sed:

grep '11:07 18:29:20' 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
154

Method 4: Search the Last n Lines for a Keyword

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

Method 5: Highlight Matches

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

Method 6: Show Context Lines Around Matches

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

Method 7: Paginated Viewing

Pipe the filtered output to more or less for page‑by‑page navigation:

# tail -n 2000 catalina.out | grep 'INFO Takes:1' --color -a2 | more
# tail -n 2000 catalina.out | grep 'INFO Takes:1' --color -a2 | less

Additional Navigation Shortcuts (within less/more)

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 – go to the last line g – go to the first line q or ZZ – quit the pager

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.