Modern Replacements for grep

Compare ripgrep, The Silver Searcher (ag) and rga as replacements for grep: defaults, file-type handling, and what each searches.

Updated

short verdict

Pick ripgrep as the default grep replacement for searching code and text: it filters by gitignore and binary status out of the box and has the broadest flag set. Choose ag if you already use it through ack.vim or ag.el. Choose rga when the files you search include PDFs, Office documents, archives or subtitles.

grep searches the files you name, line by line, and leaves recursion, ignore rules and file-type handling to you. The tools below search directories recursively and apply ignore rules by default. They differ in scope: ripgrep and ag search plain text, while rga wraps ripgrep to extract text from binary document formats before matching.

this page is for

  • Developers searching large codebases who want gitignore-aware recursive search
  • Readers who need to search PDFs, docx, epub, archives or subtitles from the command line
  • Editor users who want a search backend for Vim or Emacs
#1

ripgrep

★ 69.5kRust
details

Recursive regex search that skips gitignored, hidden and binary files by default, with the widest set of options of the three.

best for

  • Default grep replacement for code
  • Searching text in non-UTF-8 encodings or compressed files
  • Lookaround or backreference patterns

strengths

  • Respects gitignore and skips hidden and binary files; `rg -uuu` turns the filtering off
  • File type filters such as `rg -tpy foo` and `rg -Tjs foo`
  • `-E/--encoding` for UTF-16, latin-1, GBK, EUC-JP, Shift_JIS; `-z/--search-zip` for gzip, xz, zstandard and more
  • Optional PCRE2 via `-P/--pcre2` for look-around and backreferences

weaknesses

  • Default regex engine has no look-around or backreferences; you must enable PCRE2
  • Skips hidden files by default, so results differ from grep -r until you pass flags

C-based code search that reads .gitignore, .hgignore and .ignore files and searches with multiple threads.

best for

  • Existing users of ack.vim, ag.el or TextMate integration
  • Mercurial repositories that rely on .hgignore

strengths

  • Honors `.gitignore`, `.hgignore` and custom `.ignore` files
  • Pthreads multithreading, memory-mapped reads and PCRE JIT for regex searches
  • Editor integrations: Vim via ack.vim, Emacs via ag.el, TextMate
  • Installs from Homebrew, APT (`silversearcher-ag`) and DNF

weaknesses

  • Documented as a faster ack, not a grep replacement; no encoding or compressed-file flags are listed
  • Fewer documented features than ripgrep, such as no PCRE2 switch or preprocessing filters
#3

rga

★ 9.9kRust
details

Wraps ripgrep and adds adapters so the same regex search reaches inside PDFs, Office files, e-books, archives, sqlite and video subtitles.

best for

  • Searching document collections and archives
  • Researchers and sysadmins with mixed file types

strengths

  • Adapters for pandoc (docx, odt, epub, HTML), poppler (PDF) and ffmpeg (video metadata, subtitles)
  • Descends into nested archives such as zip and tar.gz
  • Caches extracted text in a ZSTD-compressed local database, which speeds up repeat searches
  • Accepts ripgrep's options and patterns; integrates with fzf

weaknesses

  • Extraction relies on external adapters such as pandoc, poppler and ffmpeg
  • Built on ripgrep, so it adds no benefit for plain source-code searches

What changes compared to grep

These differences come up first when you swap grep for one of these tools.

  • Recursive by default: you pass a directory or nothing, rather than grep's -r flag
  • Ignore rules apply: ripgrep and ag read .gitignore; ag also reads .hgignore and .ignore
  • ripgrep skips hidden and binary files unless you use `rg -uuu`
  • File type filters: `rg -tpy foo` searches only Python files, `rg -Tjs foo` excludes JavaScript
  • Regex engine: ripgrep's default lacks look-around; `-P/--pcre2` enables it, and ag uses PCRE JIT

Switching from grep

The projects document options that ease the move.

  • rga accepts all of ripgrep's standard options and patterns
  • ripgrep supports a configuration file, so you can set your preferred flags once
  • ag keeps ack-style command-line patterns, which helps if you come from ack

When not to use these

  • You need a search that runs identically on every minimal system without installing anything, since these tools are separate installs
  • You need to search binary files as raw bytes; ripgrep skips them by default and you must opt in with flags

FAQ

Are these tools drop-in replacements for grep in scripts?
Flag-level grep compatibility is not documented by the projects. The defaults differ from grep: recursive search, ignore-file filtering and skipped hidden and binary files, so test existing scripts before switching.
Which one is best for searching code?
ripgrep is the default pick. It respects gitignore, has file type filters like `-tpy`, and offers optional PCRE2. ag is also aimed at code and integrates with Vim and Emacs.
Can any of them search PDFs?
rga can. It uses poppler to extract PDF text, and it also handles docx, epub, archives and subtitles. ripgrep can reach PDFs only through its preprocessing filters.
How do I search ignored or hidden files with ripgrep?
Use `rg -uuu`, which disables the gitignore, hidden-file and binary-file filtering.

related