GNU grep
$ grep Foundation Low RiskGNU grep is the canonical Unix pattern matcher supporting basic, extended (-E), fixed-string (-F), and Perl-compatible (-P) regexes with recursive --include/--exclude-dir filters. It is ubiquitous in Linux and CI environments, though it emits plain text rather than JSON.
brew install grep Standard POSIX/GNU text search executes directly in sub-millisecond pipes; MCP adds zero value here.
Agent-Readiness Checklist
Local Probe EvidenceCaptured --help excerpt
usage: grep [-abcdDEFGHhIiJLlMmnOopqRSsUVvwXxZz] [-A num] [-B num] [-C[num]] [-e pattern] [-f file] [--binary-files=value] [--color=when] [--context[=num]] [--directories=action] [--label] [--line-buffered] [--null] [pattern] [file ...]
FCRS-1.0 6-Dimension Breakdown
Deterministic non-interactive pipe tool with --color=never and exit codes (0 match, 1 none, 2 error), but lacks --json and .gitignore awareness.
- Supports
-n,-H,--color=never, and-m <num>match limits - Plain-text line output only; no
--jsonflag
Strictly read-only line matcher with zero file mutation capabilities.
- Read-only tool operating on files and stdin
Preinstalled on virtually every Linux container; brew install grep provides ggrep on macOS alongside stock BSD grep.
- Universal Unix tool; minor BSD vs GNU flag differences (
-P) exist on macOS
Reliable baseline text search across every Unix host and pipeline when rg is unavailable.
- Supports
-F,-E,-P,-m, and--include/--exclude-dir
Foundational GNU Project utility maintained for decades under GPL-3.0-or-later.
- Official GNU Project package
Canonical GNU manual and man grep documentation.
- Official manual at gnu.org/software/grep/manual
Security, Auth & Guardrails
None required; read-only text stream and file search.
100% free, offline, and open-source (GPL-3.0-or-later).
# GNU grep Agent Rules - Always pass `--exclude-dir=.git --exclude-dir=node_modules` when running recursive `grep -r`. - Note macOS stock `grep` is BSD `grep` (`-P` fails unless `ggrep` from `brew install grep` is used); prefer `-F` or `-E` for portability.
Agent-Ready Command Recipes
Safe Read-Only Queries
grep -rnF --color=never --exclude-dir=node_modules --include='*.ts' "fetchToken" src/
Searches literally (-F) with line numbers (-n), skipping node_modules and disabling ANSI color.
grep -rnE --color=never "ERROR|FATAL" logs/
Uses POSIX extended regex (-E) to extract error lines cleanly from logs.
Strengths for Agents
- + Universally available on Linux servers, containers, and CI runners.
- +
-Ffixed-string mode avoids regex escaping bugs, and-mcaps match output.
Caveats & Pitfalls
- ! Does not respect
.gitignoreor skipnode_modules/.gitunless--exclude-diris passed. - ! GNU-only
-P(PCRE) is unavailable in macOS stock BSDgrep(requiresggrep).