file-search

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

File Search Skill

文件搜索技能

Efficient CLI search tools for AI agents.
为AI Agent打造的高效CLI搜索工具。

Tool Selection Guide

工具选择指南

TaskUseInstead of
Search text in code files
rg
(ripgrep)
grep
,
grep -r
Find files by name/path
fd
find
,
ls -R
Structural/syntax-aware code search
sg
(ast-grep)
regex hacks
Search PDFs, Office docs, archives
rga
(ripgrep-all)
manual extraction
Count lines of code by language
tokei
cloc
,
wc -l
Code stats with complexity metrics
scc
cloc
,
tokei
Decision flow: text/regex →
rg
| code structure (empty catches, function sigs, multi-line patterns) →
sg
| files by name →
fd
| PDFs/archives →
rga
| codebase stats →
tokei
/
scc
任务使用工具可替代原有工具
在代码文件中搜索文本
rg
(ripgrep)
grep
,
grep -r
按名称/路径查找文件
fd
find
,
ls -R
支持结构/语法感知的代码搜索
sg
(ast-grep)
正则表达式hack
搜索PDF、Office文档、归档文件
rga
(ripgrep-all)
手动提取内容
按语言统计代码行数
tokei
cloc
,
wc -l
包含复杂度指标的代码统计
scc
cloc
,
tokei
决策流程: 文本/正则搜索 →
rg
| 代码结构搜索(空捕获、函数签名、多行模式)→
sg
| 按名称查找文件 →
fd
| PDF/归档文件搜索 →
rga
| 代码库统计 →
tokei
/
scc

Quick Examples

快速示例

bash
rg 'def \w+\(' -t py src/          # rg: text search in Python files
rg -c 'TODO' -t js | wc -l         # rg: count first, then drill down
sg --pattern 'console.log($$$)' --rewrite 'logger.info($$$)' --lang js  # sg: structural replace
fd -g '*.test.ts' --changed-within 1d  # fd: -g for compound suffixes (NOT -e)
fd -g '*_test.go' -X rg 'func Test'   # fd+rg: find files, verify contents
rga 'quarterly revenue' docs/       # rga: search inside PDFs/archives
tokei --sort code                   # tokei: language stats
scc --wide                          # scc: complexity + COCOMO
bash
rg 'def \w+\(' -t py src/          # rg: text search in Python files
rg -c 'TODO' -t js | wc -l         # rg: count first, then drill down
sg --pattern 'console.log($$$)' --rewrite 'logger.info($$$)' --lang js  # sg: structural replace
fd -g '*.test.ts' --changed-within 1d  # fd: -g for compound suffixes (NOT -e)
fd -g '*_test.go' -X rg 'func Test'   # fd+rg: find files, verify contents
rga 'quarterly revenue' docs/       # rga: search inside PDFs/archives
tokei --sort code                   # tokei: language stats
scc --wide                          # scc: complexity + COCOMO

Best Practices

最佳实践

  1. Start narrow. Specify types (
    -t
    ,
    --lang
    ,
    -e
    ), scope dirs, count first (
    rg -c
    ).
  2. Exclude noise (
    -g '!vendor/'
    ,
    fd -E node_modules
    ).
  3. --json
    for programmatic processing.
  4. rg ≠ fd types.
    rg -t ts
    includes
    .tsx
    ;
    fd -e ts
    does NOT. No
    -t tsx
    in rg.
See references/search-strategies.md.
  1. 从窄范围开始。 指定类型(
    -t
    --lang
    -e
    )、限定目录范围、先统计数量(
    rg -c
    )。
  2. 排除干扰内容
    -g '!vendor/'
    fd -E node_modules
    )。
  3. 开启
    --json
    参数用于程序化处理。
  4. rg和fd的类型规则不同。
    rg -t ts
    会包含
    .tsx
    文件;
    fd -e ts
    不会。rg中没有
    -t tsx
    参数。
参见 references/search-strategies.md

Beyond Local Files

超出本地文件范围

If local search finds nothing and context lives in issues/PRs/external docs — hand off (
gh
, Jira, WebFetch). Issue keys in comments signal this.
See references/remote-handoff.md.
如果本地搜索没有结果,且上下文存放在issues/PRs/外部文档中 —— 移交处理(
gh
、Jira、WebFetch)。评论中的Issue编号可识别此类场景。
参见 references/remote-handoff.md

References

参考资料

TopicFile
rg flags, patterns, recipesreferences/ripgrep-patterns.md
ast-grep patterns by languagereferences/ast-grep-patterns.md
fd flags, usage, fd+rg combosreferences/fd-guide.md
rga formats, usage, cachingreferences/rga-guide.md
tokei and scc usagereferences/code-metrics.md
Search targeting strategiesreferences/search-strategies.md
Tool comparison and decision guidereferences/tool-comparison.md
Remote context handoff guidereferences/remote-handoff.md
主题文件路径
rg参数、模式、使用示例references/ripgrep-patterns.md
按语言划分的ast-grep匹配模式references/ast-grep-patterns.md
fd参数、用法、fd+rg组合使用技巧references/fd-guide.md
rga支持格式、用法、缓存配置references/rga-guide.md
tokei与scc用法references/code-metrics.md
搜索目标策略references/search-strategies.md
工具对比与决策指南references/tool-comparison.md
远程上下文移交指南references/remote-handoff.md