Scripts2026年7月23日·1 分钟阅读

The Silver Searcher (ag) — Lightning-Fast Code Search from the Terminal

A code-searching tool similar to ack but optimized for speed. ag recursively searches directories for a regex pattern while respecting .gitignore rules, delivering results 5-10x faster than ack and on par with ripgrep.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
The Silver Searcher
直接安装命令
npx -y tokrepo@latest install d77daba2-8658-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

The Silver Searcher (ag) is a code-searching tool originally inspired by ack but rewritten in C for raw speed. It automatically skips files listed in .gitignore and .hgignore, making it ideal for searching large codebases without wading through build artifacts or vendor directories.

What The Silver Searcher Does

  • Recursively searches directories for regex or literal patterns at high speed
  • Honors .gitignore, .hgignore, and custom ignore files out of the box
  • Prints results with filenames, line numbers, and color highlighting
  • Supports PCRE-style regular expressions for complex pattern matching
  • Searches compressed files and allows file-type filtering with flags

Architecture Overview

ag is written in C and uses POSIX threads to parallelize directory traversal and file searching. It memory-maps files for fast I/O, builds an ignore-rule tree from .gitignore and similar files at startup, and applies those rules during traversal so excluded paths are never opened. Pattern matching is handled by the PCRE library.

Self-Hosting & Configuration

  • Ships as a single binary with no runtime dependencies beyond libc and PCRE
  • Available in all major package managers (brew, apt, yum, pacman, choco)
  • Configure default flags in a ~/.agrc file (e.g., --hidden, --depth)
  • Override ignore rules per-project with a .ignore or .agignore file
  • Integrates with editors via plugins for Vim (ag.vim), Emacs (ag.el), and VS Code

Key Features

  • Typically 5-10x faster than ack on large repositories
  • Automatic .gitignore awareness removes the need for manual exclude lists
  • Colored, grouped output is easy to scan in a terminal
  • Pager support pipes long results through less automatically
  • Broad platform support across Linux, macOS, FreeBSD, and Windows

Comparison with Similar Tools

  • ripgrep (rg) — newer Rust-based successor, generally faster on modern hardware but ag remains well-established
  • ack — the Perl-based predecessor; ag is a performance-oriented reimplementation
  • grep -r — universal but slower and requires manual ignore configuration
  • git grep — fast inside git repos but limited to tracked files only
  • ugrep — newer C++ grep alternative with ag-compatible output

FAQ

Q: How does ag compare to ripgrep? A: ripgrep is generally faster in benchmarks, especially on very large repos. ag is still fast and widely installed, making it a solid choice when rg is unavailable.

Q: Can ag search binary files? A: By default ag skips binary files. Use the --search-binary flag to include them.

Q: Does ag support multiline search? A: ag does not natively support multiline patterns. Use ripgrep with the -U flag or pcregrep -M for that.

Q: How do I search only specific file types? A: Use file-type flags like ag --python "pattern" or provide a glob with -G "*.ts".

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产