ripgrep (rg)

Updated

September 4, 2026

Overview

ripgrep (rg) recursively searches the filesystem for a regex pattern. It respects .gitignore by default, skips hidden/binary files sensibly, and is typically much faster than grep -r on large codebases.

sudo apt install ripgrep
sudo dnf install ripgrep

Syntax

rg [options] PATTERN [PATH...]

Common Options

Option Description
-i Case insensitive
-w Whole word
-t TYPE File type (py, rust, go, md, …)
-T TYPE Exclude type
-g GLOB Include/exclude globs (-g '!**/vendor/**')
-C N / -A / -B Context lines
-n / -N Line numbers on/off
-l Files with matches
-c Count per file
-o Only matching part
-v Invert match
-u / -uu / -uuu Unrestricted (ignore ignore rules / hidden / binary)
--hidden Search hidden files
--no-ignore Don’t respect ignore files
-F Fixed string (no regex)
-P PCRE2 (if built with it)
-z Search compressed files
--json JSON lines output
-0 with -l NUL file names
--stats Search statistics

Key Use Cases

  1. Codebase search ignoring build artifacts
  2. Language-scoped searches (-t go)
  3. Incident hunting in logs (with -uu when needed)
  4. Pre-commit / review “where is this symbol?”

Examples with Explanations

Basics

rg 'process_data'
rg -i 'todo|fixme'
rg -w 'main'

Types and globs

rg -t python 'import os'
rg -t go -t rust 'TODO'
rg -g '*.qmd' 'include::'
rg -g '!**/node_modules/**' 'left-pad'

Context and files

rg -C 3 'panic\('
rg -l 'DEPRECATED'
rg -c 'error' /var/log 2>/dev/null

One-liner recipes

# Who calls this function?
rg -n 'funcName\(' -t go

# JSON for tools
rg --json 'pattern' | head

# Replace workflow: list then edit
rg -l 'OldName' | xargs -r sed -i 's/OldName/NewName/g'   # review first!

# Fixed string with special chars
rg -F 'C++' -t md

Notes & Pitfalls

  • Default ignore can hide hits in build/, dist/, or gitignored configs—use -u deliberately.
  • Binary matches are skipped unless unrestricted; good for speed, surprising for firmware blobs.
  • Multiline requires -U / --multiline (see man).
  • grep is still required for POSIX scripts and tiny systems without rg.

2026-relevant notes

  • rg + fd is the standard modern search pair; IDEs shell out to similar engines.
  • For huge monorepos, prefer type/glob filters over unconstrained -uuu.
  • PCRE2 (-P) is optional at build time—don’t assume it on every distro build.

Comparison to alternatives

Tool Role
rg Fast recursive search
grep -R Portable
ag / ack Older dev search tools
git grep Only tracked files

Additional Resources

  • man rg
  • BurntSushi/ripgrep user guide