Getting Started with ripgrep

ripgrep (rg) is a line-oriented search tool that recursively searches your current directory for a regex pattern. It's designed to be fast, user-friendly, and to do the right thing by default — like respecting your .gitignore.

This guide will get you productive in about 10 minutes.

1. Installation

The quickest way to install ripgrep is via a package manager for your platform:

macOS bash
brew install ripgrep
Windows (Winget) powershell
winget install BurntSushi.ripgrep.MSVC
Ubuntu / Debian bash
sudo apt install ripgrep
Cargo (any platform) bash
cargo install ripgrep

For all platforms and installation methods, see the Download page. After installation, verify it works:

rg --version
# ripgrep 15.1.0 (rev b4cfbdf2af) +SIMD +AVX (compiled)

The basic syntax is rg PATTERN. ripgrep will search all files in the current directory and subdirectories, skipping hidden files and anything listed in your .gitignore.

Search for 'TODO' in the current directory bash
rg 'TODO'

Output looks like this:

src/main.rs
14: // TODO: handle edge case
87: // TODO: write tests

src/lib.rs
203:    // TODO: optimize this loop

Each result shows the file path, then each matching line with its line number and the match highlighted in color.

Tip: ripgrep treats your pattern as a regular expression by default. To search for a literal string (no regex), use rg -F 'literal.string'.

3. Common search patterns

# Case-insensitive search
rg -i 'error'

# Match whole words only (not "errors" or "errored")
rg -w 'error'

# Search for multiple patterns at once
rg -e 'TODO' -e 'FIXME' -e 'HACK'

# Invert the match — show lines that do NOT contain pattern
rg -v 'test'

# Search with context — 2 lines before and after
rg -C 2 'panic'

# Only 3 lines after each match
rg -A 3 'fn main'

4. Filtering files

By file type

Use -t to restrict the search to a specific language or file type. ripgrep knows about 200+ types.

# Only search Python files
rg 'def ' -t py

# Only search Rust files
rg 'fn main' -t rust

# Only search JavaScript and TypeScript
rg 'console.log' -t js -t ts

# See all built-in types
rg --type-list

By glob pattern

# Only .config.ts files
rg 'export' --glob '*.config.ts'

# Exclude a directory
rg 'TODO' --glob '!node_modules/**'

# Multiple globs
rg 'import' -g '*.ts' -g '!*.test.ts'

Overriding ignore rules

# Include hidden files (e.g., .env, .github/)
rg -. 'SECRET'

# Ignore .gitignore rules (search everything)
rg --no-ignore 'pattern'

# Ignore everything — truly search all files
rg -uu 'pattern'

5. Understanding the output

# Only list file names (no line content)
rg -l 'TODO'

# Count matches per file
rg -c 'import'

# Show line numbers explicitly (default when output is a terminal)
rg -n 'pattern'

# JSON output for scripting
rg --json 'pattern'

# Quiet — no output, just exit code (0 = match found, 1 = no match)
rg -q 'pattern' && echo "Found it!"

6. Next steps

You now know enough to use ripgrep productively every day. To go deeper: