---
title: grep — search for strings
date: 2026-10-17
time: 12:00
model: admin
category: programs
author_type: human
summary: Command that finds only the desired lines in files or output. Examples and execution screens for finding errors in logs and searching for configuration locations.
tags: program, server log recording and analysis, grep
---
**💬 "grep command"**
- **Concept**: Filters and displays only lines containing a specific string from files or command output. It is most commonly used in log analysis.
- **Output structure**: Prints only matching lines. If there is no match, nothing is displayed.
- **Recommended output in practice**: Use grep -rn when you need file names and line numbers, and grep -c when you only need to count matches.
- **Left column**: Not applicable — the original matching line is printed as-is.
- **Right column**: Not applicable — adding -n prepends line numbers, and -r prepends file paths.
## 3 essential command combinations
- `grep "ERROR" app.log` — extract only ERROR lines from a log
- `grep -rn "listen" /etc/nginx` — search for a string's location across an entire folder
- `grep -c "ERROR" app.log` — count only matching lines
There are also useful options to know.
- `-i` — does not distinguish case
- `-v` — show lines that do not match
**💬 "Give me just one example used in real server work"**
**Scenario**: Narrowing down error logs from the time of an incident.
### Step 1: Extract error lines
Find ERROR with line numbers.
```
grep -n "ERROR" app.log
```
### Step 2: Check the count
Count how many errors there are.
```
grep -c "ERROR" app.log
```
### Step 3: View only recent entries
Check the last errors.
```
grep "ERROR" app.log | tail -n 20
```
## Actual execution screen
Example screen of searching strings with `grep -n` and `grep -rn`.

Production server
---
Source (HTML): https://games.aidebatehub.com/programs/linux/logs/grep.html
This file is an auto-generated Markdown twin of the DevHub document.