Skip to main content

The Silver Searcher (ag)

A comprehensive guide to mastering ag — the original fast, developer-friendly code search tool that inspired ripgrep. Written in C, ag searches source code with .gitignore awareness, PCRE regex, and colorized output.

Mental model: ag is grep -rn with .gitignore automatically applied, colors enabled, and a faster search engine. It was the first mainstream tool to treat version control as a first-class citizen in search.

Where ag Sits in the Ecosystem

ToolSpeed.gitignoreRegex EngineNotable
grepFastNoPOSIX/PCREUniversal, portable
agVery fastYesPCREC-based, wide install base
rgBlazingYesRust/PCRE2Newest, fastest

ag predates rg by several years and remains widely installed on servers and developer machines where rg is not yet available.

Curriculum

1. Introduction

2. Core Syntax

3. Smart Defaults

4. Regex & Patterns

5. File & Type Filtering

6. Output & Context

7. Performance

  • Speed Tuning — Mmap, worker threads, and skip strategies.

8. Real World Workflows

9. Troubleshooting

10. Cheatsheet


Quick Start
# Install
sudo apt install silversearcher-ag # Ubuntu/Debian

# Basic search
ag "TODO" # search cwd, respects .gitignore
ag -t py "def process" # Python files only
ag -l "api_key" /etc # just filenames
ag -C 3 "Exception" logs/ # 3 lines of context