ggreer/the_silver_searcher
FreeA code-searching tool similar to ack, but faster.
FreeFree tier
About ggreer/the_silver_searcher
The Silver Searcher (ag) is a code-searching tool designed for incredible speed, often outperforming ack by an order of magnitude. It leverages multiple CPU cores via Pthreads, uses mmap() for efficient file reading, implements Boyer-Moore for literal string searches, and employs PCRE's JIT compiler for regex searches. It automatically respects ignore patterns from .gitignore, .hgignore, and custom .ignore files, reducing the search space. The tool is stable, actively maintained, and available on major platforms through package managers or source builds.
Key Features
Order of magnitude faster than ack; 34x faster in a benchmark on an 8GB code directory
Uses Pthreads to search files in parallel across multiple CPU cores
Employs mmap() for file reading instead of buffered I/O
Boyer-Moore string search for literal patterns
PCRE's JIT compiler for fast regex searching (when built with PCRE >= 8.21)
Calls pcre_study() before executing regex on every file for optimization
Ignores file patterns from .gitignore, .hgignore, and custom .ignore files
Non-regex ignore patterns are loaded into arrays and binary searched (instead of fnmatch)
Short command name 'ag' all on the home row
Stable with ongoing feature additions and performance improvements
Pros & Cons
Pros
- Extremely fast compared to alternative tools like ack
- Automatic respect for version control ignore files reduces search scope
- Open source and free to use under a permissive license
- Cross-platform support with many package managers available
- Active maintenance and community support on GitHub
Cons
- Command-line only, lacks a graphical user interface
- Configuration is limited to ignore files; no built-in filtering by file type or date
- Windows support relies on unofficial builds or package managers, not first-class
- Requires familiarity with command-line regex syntax for advanced queries
Best For
Searching large codebases for variable names, functions, or commentsFinding usage of specific APIs or patterns across a projectRefactoring code by locating all occurrences of a code snippetDebugging by searching for error messages or suspicious patternsExploring unfamiliar codebases to understand structure and dependencies
FAQ
How is The Silver Searcher so fast?
It uses Pthreads for parallel CPU usage, mmap() for efficient file reading, Boyer-Moore string search for literals, PCRE's JIT compiler for regex (if PCRE >= 8.21), pcre_study() optimization, and binary-searched ignore patterns instead of fnmatch.
Does The Silver Searcher respect .gitignore files?
Yes, it automatically ignores file patterns from .gitignore, .hgignore, and custom .ignore files, which helps reduce the search space significantly.
How do I install The Silver Searcher on macOS?
On macOS, you can install it using Homebrew with 'brew install the_silver_searcher' or MacPorts with 'port install the_silver_searcher'.
How do I install The Silver Searcher on Ubuntu/Debian?
On Ubuntu >= 13.10 or Debian >= 8, use 'apt-get install silversearcher-ag'. On other Linux distributions, see the README for specific package commands.