rg(1)
A fast, line-oriented search tool that recursively searches directories for a regex pattern, similar to grep but with sensible defaults and better performance.
Synopsis
rg [OPTIONS] PATTERN [PATH...]Description
rg (ripgrep) is a modern replacement for grep and similar tools. It searches files for lines matching a regular expression pattern, automatically respecting .gitignore files and skipping binary files and hidden directories by default.
It uses parallel processing and regex optimizations to deliver results much faster than traditional grep, and provides intuitive defaults that work well for most use cases without extensive flag configuration.
Common options
| Flag | What it does |
|---|---|
-i, --ignore-case | Case insensitive search |
-w, --word-regexp | Match only whole words, as if surrounded by \b |
-c, --count | Only show count of matching lines per file, not the lines themselves |
-l, --files-with-matches | Only show filenames containing matches, not the matching lines |
-A NUM, --after-context NUM | Show NUM lines of context after each match |
-B NUM, --before-context NUM | Show NUM lines of context before each match |
-C NUM, --context NUM | Show NUM lines of context before and after each match |
-n, --line-number | Show line numbers (on by default) |
-H, --with-filename | Show filename for each match (on by default for multiple files) |
-t TYPE, --type TYPE | Search only files of given type (e.g., rust, python, javascript) |
-g GLOB, --glob GLOB | Include/exclude files matching glob pattern |
--no-ignore | Don't respect .gitignore files |
Examples
Search for the word TODO in all files under current directory
rg 'TODO' .Case-insensitive search for 'error' in log files
rg -i 'error' /var/logSearch for whole word 'main' in the src directory
rg -w 'main' src/Show 2 lines of context before and after panic! matches
rg -B2 -A2 'panic!' .List only filenames containing 'deprecated' in src/
rg -l 'deprecated' src/Search for function definitions in Rust files only
rg -t rust 'fn ' src/Count import statements in Python files
rg -c '^import' --type python .Search for pattern only in test files matching the glob
rg 'pattern' -g '*.test.js'