Back to commands

Linux Survival Basics

Read-only, can be slow

Find the Exact Log Line Before You Scroll

A log file contains likely failures, but you need line numbers so you can inspect context around the match.

Command

grep -inE 'error|failed|denied|timeout' /var/log/nginx/error.log

Before you run this

System impact: Read-only. Can create load on large logs, directories, filesystems, or process tables.

When not to use it: Do not assume these four words catch every failure; applications often log custom error language.

Expected output

Matching log lines prefixed by their line numbers.

System impact

Read-only, can be slow. Nothing changes. The command prints matching lines with line numbers for follow-up inspection.

May require elevated permissions on protected paths or service-owned files.

Scope this to the smallest useful path or service on busy systems.

Recovery / rollback: no state is changed.

When to use it

Use this when a first-pass grep finds failures and you need the surrounding context next.

When not to use it

Do not assume these four words catch every failure; applications often log custom error language.

Watch this command run

Command transcript

This sanitized transcript shows the commands and output shape without exposing host details.

demo@lab:~$

$ grep -inE 'error|failed|denied|timeout' /var/log/nginx/error.log

2:2026/06/25 10:01:42 [error] 11#11: *7 connect() failed (111: Connection refused) while connecting to upstream
4:2026/06/25 10:03:16 [error] 11#11: *9 access forbidden by rule, client: 203.0.113.44
5:2026/06/25 10:04:33 [error] 11#11: *10 upstream timed out while reading response header

$ grep -inE 'error|failed|denied|timeout' /var/log/nginx/error.log | tail -20

2:2026/06/25 10:01:42 [error] 11#11: *7 connect() failed (111: Connection refused) while connecting to upstream
4:2026/06/25 10:03:16 [error] 11#11: *9 access forbidden by rule, client: 203.0.113.44
5:2026/06/25 10:04:33 [error] 11#11: *10 upstream timed out while reading response header

$ sed -n '2,5p' /var/log/nginx/error.log

2026/06/25 10:01:42 [error] 11#11: *7 connect() failed (111: Connection refused) while connecting to upstream
2026/06/25 10:02:05 [warn] 11#11: upstream server temporarily disabled
2026/06/25 10:03:16 [error] 11#11: *9 access forbidden by rule, client: 203.0.113.44
2026/06/25 10:04:33 [error] 11#11: *10 upstream timed out while reading response header
View commands shown

These are the commands shown in the sanitized transcript.

Commands shown

  1. grep -inE 'error|failed|denied|timeout' /var/log/nginx/error.log
  2. grep -inE 'error|failed|denied|timeout' /var/log/nginx/error.log | tail -20
  3. sed -n '2,5p' /var/log/nginx/error.log

next steps

Related commands

Linux Survival Basics Can be slow

Find Errors Before Reading Every Log Line

The error was in the log. The problem was finding it without reading noise.

grep -iE 'error|failed|denied|timeout' /var/log/nginx/error.log | tail -40
Linux Survival Basics Can be slow

Show Only Recent Errors

The log had old failures too. I only cared about the newest ones.

grep -iE 'error|failed|denied|timeout' /var/log/nginx/error.log | tail -10
Cybersecurity Triage Can be slow

Find Warnings in Apt Terminal Logs

The package installed, but the terminal log may still contain the warning that matters.

grep -Ei 'warning|error|failed|dpkg' /var/log/apt/term.log
Linux Survival Basics Read-only

Find Which Package Owns a File

That binary came from somewhere. dpkg can tell you where.

dpkg-query -S /usr/sbin/nginx
Study mapping

Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.

  • lpic1:103-gnu-unix-commands
  • lfcs:essential-commands
  • linuxplus:automation-scripting
  • linuxplus:provisional
  • risk:read-only

Useful for

  • LPIC-1 style command-line practice
  • LFCS style performance tasks
  • Linux+ style troubleshooting review

Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.