What is The Silver Searcher (ag)?
ag (The Silver Searcher) is a code-search tool written in C by Geoff Greer, released in 2011. It was the first widely adopted tool to combine three features that developers needed:
- Recursive search — no need for
find | xargs grep .gitignoreawareness — automatically skip build artifacts- PCRE regex — full Perl-compatible regex without extra flags
It was named "Silver Searcher" as a riff on "Ack" (a Perl-based search tool, i.e. the "Ack Searcher"), with silver being faster than gold but less precious than a new tool — a playful nod to the ecosystem.
Why ag Still Matters
While rg (ripgrep) is faster in benchmarks, ag remains relevant because:
- Wide availability:
silversearcher-agis in every major Linux distribution's default package repository - Mature ecosystem: Many older Vim/Emacs plugins (
ack.vim,helm-ag) are wired toag - Stable behavior: No breaking changes over many years
How ag Works Internally
When you run ag pattern /dir:
- It reads
.gitignore,.hgignore,.agignore, and.ignorefiles - It builds an in-memory exclusion tree
- Worker threads traverse directories and read files in parallel using memory-mapped I/O (
mmap) - Each thread runs PCRE regex matching against the file content
- Results are collected and displayed with colors and line numbers
ag vs rg: Practical Differences
# ag: full PCRE by default, no extra flag needed
ag "(?<=user_id=)\d+" log.txt
# rg: requires -P for PCRE2 lookarounds
rg -P "(?<=user_id=)\d+" log.txt
# ag: uses --[language] flag
ag --python "def process"
# rg: uses -t flag
rg -t py "def process"
Both produce equivalent colorized, grouped output. Choose ag when it is already installed or when your editor tooling expects it.