ripgrep (rg)
Overview
ripgrep (rg) is a line-oriented search tool that recursively searches your current directory for a regex pattern. It respects .gitignore rules by default and is designed to be significantly faster than standard grep.
Syntax
rg [options] PATTERN [PATH...]Common Options
| Option | Description |
|---|---|
-i, --ignore-case |
Search case-insensitively |
-w, --word-regexp |
Match full words only |
-t, --type TYPE |
Search only files matching file type (e.g., -t py, -t rust) |
-T, --type-not TYPE |
Exclude files of a specific type |
-g, --glob GLOB |
Include or exclude files/directories using glob patterns |
-C, --context NUM |
Show NUM lines of contextual output before and after matches |
-l, --files-with-matches |
Print only the names of matching files |
-u, --unrestricted |
Don’t respect .gitignore (use -uu for hidden files, -uuu for binary files) |
Key Use Cases
- Ultra-fast codebase searching in large projects.
- Filtering search results by language file types (
-t). - Searching while ignoring generated build outputs and git-ignored paths automatically.
Examples with Explanations
Example 1: Basic Search
rg "process_data"Recursively searches for process_data in all non-ignored files in the current working directory.
Example 2: Searching Specific File Types
rg -t python "import os"Searches for import os strictly inside Python files (.py).
Understanding Output
Output is colorized by default when run in an interactive terminal. Each match section opens with the relative file path, followed by matching line numbers and highlighted line contents.