← 返回 CLI 目录 抓取的
GNU grep
$ grep 基金会 低风险 GNU · 文件检索与编辑 · GPL-3.0-or-later · macos / linux / windows
GNU grep 是经典的 Unix 模式匹配工具,支持基础正则、扩展正则(-E)、固定字符串(-F)及 Perl 兼容正则(-P),并支持递归 --include/--exclude-dir 过滤。它在 Linux 与 CI 环境中无处不在,但输出为纯文本而非 JSON。
FCRS-1.0 综合评分
85 /100
良好 (Good)
高置信度 (实测)
零摩擦安装命令
brew install grep CLI vs MCP 选型建议 仅 CLI 可用
标准 POSIX/GNU 文本搜索直接在毫秒级管道中运行,封装为 MCP 没有任何收益。
Agent 友好度体检单
本地探针实测证据 — 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
✓ 只读模式开关
✓ 支持 NO_COLOR
— 自省/Schema 发现
— 官方 SKILL.md
实测版本
grep (BSD grep, GNU compatible) 2.6.0-FreeBSD
冷启动耗时
2 ms
退出码 (help / 非法参数)
2 / 2
NO_COLOR 无色码污染 / 无 TTY 不挂起
Yes / Safe
抓取的 --help 摘要
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 六维评分拆解
Agent 友好度 17 / 25
确定性的非交互管道工具,支持 --color=never 与清晰退出码(0 匹配、1 无匹配、2 错误),但缺少 --json 与 .gitignore 识别。
- Supports
-n,-H,--color=never, and-m <num>match limits - Plain-text line output only; no
--jsonflag
安全与权限边界 24 / 25
严格只读的按行匹配工具,不具备任何修改文件的能力。
- Read-only tool operating on files and stdin
安装与运行摩擦 13 / 15
几乎所有 Linux 容器均已预装;macOS 通过 brew install grep 可安装 ggrep 以替代自带 BSD grep。
- Universal Unix tool; minor BSD vs GNU flag differences (
-P) exist on macOS
能力覆盖与边际价值 12 / 15
在缺少 rg 的任意 Unix 主机与管道中都是可靠的基线文本搜索工具。
- Supports
-F,-E,-P,-m, and--include/--exclude-dir
维护与来源背书 10 / 10
GNU 基金会核心基础工具,遵循 GPL-3.0-or-later 持续维护数十年。
- Official GNU Project package
文档与可验证性 9 / 10
拥有权威的 GNU 官方手册与 man grep 文档。
- Official manual at gnu.org/software/grep/manual
安全边界、鉴权与放权指南
鉴权方式
无需鉴权
凭证存储位置
无需凭据;本地只读文本流与文件搜索。
潜在副作用
只读查询
费用与配额提示
100% 免费、离线、开源(GPL-3.0-or-later)。
可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# 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 高频安全命令配方
只读查询(安全推荐)
在 TypeScript 文件中递归搜索字面量
grep -rnF --color=never --exclude-dir=node_modules --include='*.ts' "fetchToken" src/
使用 -F 字面量匹配与 -n 行号输出,跳过 node_modules 并禁用 ANSI 颜色。
跨日志文件执行扩展正则搜索
grep -rnE --color=never "ERROR|FATAL" logs/
利用 POSIX 扩展正则(-E)从日志目录中提取错误行。
核心优势
- + 在 Linux 服务器、容器与 CI 运行环境中普遍预装。
- +
-F字面量模式可避免正则转义错误,-m可限制匹配条数。
注意事项与踩坑点
- ! 默认不读取
.gitignore,递归搜索时必须显式传入--exclude-dir跳过node_modules/.git。 - ! GNU 特有的
-P(PCRE)在 macOS 原生 BSDgrep中不可用,需调用ggrep。
已验证兼容的 Agent 宿主
Claude Code Codex CLI Gemini CLI