Merry Christmas & Happy 2027! Less downtime. More good times. Celebrating 13 years of sorlavit.com
Skip to content
Sorlavit KimIT Support, Network & Infrastructure Services Let’s talk

ปุ่มแปลไทยจะเปิดบทความผ่าน Google Translate เพื่อแปลอัตโนมัติ โดยคงโค้ดและคำสั่งไว้ตามต้นฉบับ

Linux Commands / IT Support Guides

Search Linux logs with grep and context

A matching error line rarely tells the full story. Include nearby lines to see the request, retry and preceding cause without copying an entire log file.

Compiled for Sorlavit Kim · Published · Updated · 1 min read

Environment and inputs: Linux · Bash-compatible shell; package and service names vary by distribution

Try the diagnostic command

Use the stated shell and platform. Replace sample domains, addresses, services and paths with values from the system you are authorized to support.

grep -n -i -C 3 -- 'connection refused' /var/log/app/app.log

How to read the result

The query uses a literal phrase that has no regex metacharacters, ignores case and includes three context lines on each side. Line numbers help another engineer locate the same passage.

What to do next

Compare repeated matches by timestamp and destination. Distinguish a startup retry that recovered from a persistent failure affecting the user's request.

Before you make a change

Replace the log path and redact credentials. Rotated compressed logs require another reader, and a missing match can reflect a different message or logging level.

Share this article

Back to results