Ripgrep (rg) – Fast Recursive Search Tool

4.9 Stars
Version 14.1.0
6 MB

Search Code Lightning Fast with Ripgrep

Ripgrep (rg) has rapidly become the search tool of choice for developers who need to search through large codebases quickly and efficiently. Built with Rust for exceptional performance, ripgrep combines the user-friendliness of The Silver Searcher (ag) with speed that often exceeds even GNU grep, while adding modern features like automatic gitignore respect and smart case sensitivity.

Created by Andrew Gallant (BurntSushi), ripgrep represents the culmination of lessons learned from previous search tools. Its performance comes from efficient use of Rust’s regex crate, memory-mapped file access, and parallelization. These technical foundations make ripgrep not just incrementally faster, but often dramatically faster than alternatives when searching large directories.

Installation

Linux Installation

Ubuntu/Debian:

sudo apt install ripgrep

Fedora:

sudo dnf install ripgrep

Arch Linux:

sudo pacman -S ripgrep

Using Cargo:

cargo install ripgrep

macOS Installation

brew install ripgrep

Windows Installation

choco install ripgrep
# or
scoop install ripgrep
# or
winget install BurntSushi.ripgrep

Basic Usage

Simple Search

Search for a pattern in current directory recursively:

rg "search pattern"

Search in specific directory:

rg "pattern" /path/to/directory

Search in specific file:

rg "pattern" filename.txt

Case Sensitivity

Case insensitive search:

rg -i "pattern"

Smart case (insensitive unless pattern contains uppercase):

rg -S "Pattern"

Line Numbers and Context

Show line numbers (default):

rg -n "pattern"

Show context lines:

# 2 lines before and after
rg -C 2 "pattern"

# 3 lines before
rg -B 3 "pattern"

# 3 lines after
rg -A 3 "pattern"

File Filtering

File Type Filtering

Search only in specific file types:

rg -t py "import"      # Python files only
rg -t js "function"    # JavaScript files only
rg -t rust "fn main"   # Rust files only

Exclude file types:

rg -T js "pattern"     # Exclude JavaScript files

List available types:

rg --type-list

Glob Patterns

Include files matching glob:

rg -g "*.py" "pattern"
rg -g "src/**/*.js" "function"

Exclude files matching glob:

rg -g "!*.min.js" "pattern"
rg -g "!node_modules" "pattern"

Hidden and Ignored Files

Search hidden files:

rg --hidden "pattern"

Don’t respect .gitignore:

rg --no-ignore "pattern"

Search everything (hidden + ignored):

rg -uuu "pattern"

Regular Expressions

Basic Regex

Ripgrep uses Rust’s regex syntax:

# Match email addresses
rg "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}"

# Match IP addresses
rg "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"

# Match function definitions
rg "function\s+\w+\s*\("

Word Boundaries

Match whole words only:

rg -w "word"

Literal Search

Search for literal string (no regex):

rg -F "exact.string[0]"

Multiline Search

Enable multiline matching:

rg -U "start.*?end"

Output Formatting

Output Control

Only show filenames:

rg -l "pattern"

Only show matching parts:

rg -o "pattern"

Count matches:

rg -c "pattern"

Show match statistics:

rg --stats "pattern"

Color and Formatting

Force color output (useful for piping):

rg --color=always "pattern" | less -R

JSON output:

rg --json "pattern"

Replacement

Show what replacement would look like:

rg "old" --replace "new"

Performance Features

Parallel Search

Control thread count:

rg -j 4 "pattern"   # Use 4 threads

Memory Mapping

Disable memory mapping for special filesystems:

rg --no-mmap "pattern"

Binary Files

Search binary files:

rg -a "pattern"

Practical Examples

Find TODO Comments

rg "TODO|FIXME|HACK|XXX" -t py

Find Function Definitions

# Python functions
rg "def \w+\(" -t py

# JavaScript functions
rg "function \w+|const \w+ = \(" -t js

# Go functions
rg "func \w+\(" -t go

Find Import Statements

rg "^import|^from .* import" -t py

Search and Replace Workflow

# Find all occurrences
rg "oldFunction" -l

# Preview replacements
rg "oldFunction" --replace "newFunction"

# Actually replace (using sed)
rg -l "oldFunction" | xargs sed -i 's/oldFunction/newFunction/g'

Find Large Files

Combine with other tools:

rg --files | xargs ls -la | sort -k5 -n | tail -20

Configuration

Configuration File

Create ~/.ripgreprc:

# Smart case by default
--smart-case

# Add custom type
--type-add
web:*.{html,css,js}

# Default context
--context=2

# Ignore additional directories
--glob=!.git
--glob=!node_modules
--glob=!vendor

Set environment variable:

export RIPGREP_CONFIG_PATH="$HOME/.ripgreprc"

Custom File Types

Define custom types:

rg --type-add 'config:*.{json,yaml,yml,toml}' -t config "pattern"

Integration with Other Tools

fzf Integration

# Interactive search
rg --line-number "" | fzf --preview 'bat --color=always {1} --highlight-line {2}'

Vim Integration

Use ripgrep for :grep in Vim:

set grepprg=rg\ --vimgrep
set grepformat=%f:%l:%c:%m

VS Code Integration

VS Code uses ripgrep by default for its search functionality.

Comparison with Alternatives

vs grep

– Much faster on large codebases
– Automatic recursion
– Smart defaults (respects .gitignore)
– Better Unicode support

vs ag (The Silver Searcher)

– Generally faster
– Better Windows support
– More consistent regex behavior
– Active development

vs ack

– Significantly faster
– Memory-mapped file access
– Built-in parallelization

Ripgrep represents the current state of the art in code search tools. Its combination of speed, smart defaults, and powerful features make it an essential tool for anyone who regularly searches through codebases. The investment in learning ripgrep’s options pays dividends in dramatically faster search workflows.

Developer: Andrew Gallant

Download Options

Download Ripgrep (rg) – Fast Recursive Search Tool

Version 14.1.0

File Size: 6 MB

Download Now
Safe & Secure

Verified and scanned for viruses

Regular Updates

Always get the latest version

24/7 Support

Help available when you need it