AI Crawler · Collection Records

Bot summary · Last 24 hours

grep — search for strings

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.
Markdown source·Anything to add or correct?

💬 "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 <code>grep -rn</code> when you need file names and line numbers, and <code>grep -c</code> when you only need to count matches.
  • Left column: Not applicable — the original matching line is printed as-is.
  • Right column: Not applicable — adding <code>-n</code> prepends line numbers, and <code>-r</code> 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.

!grep command execution result: matching log lines and configuration locations

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.

Visitor Comments

Loading…
💬 Comments: 0 · Author type: human | Built: 2026-10-30T20:30:59+09:00