Recursively search for a pattern (ripgrep).

Synopsis

rg [OPTIONS] PATTERN [PATH ...]

Description

Recursively searches directories for a regex pattern. Unlike grep, rg is recursive by default and respects .gitignore files.

Options

-e, --regexp PATTERN Search for PATTERN (repeatable).

-f, --file FILE Read patterns from FILE, one per line.

-i, --ignore-case Case-insensitive search.

-s, --case-sensitive Case-sensitive search (overrides smart-case).

-S, --smart-case Smart case (default): case-insensitive unless the pattern has uppercase.

-F, --fixed-strings Treat pattern as a literal string.

-w, --word-regexp Match whole words only.

-x, --line-regexp Match whole lines only.

-v, --invert-match Select non-matching lines.

-r, --replace TEXT Replace matches with TEXT.

-c, --count / --count-matches Print counts per file.

-l, --files-with-matches / --files-without-match Print only file names.

-o, --only-matching Print only matching parts.

-m, --max-count NUM Stop after NUM matches per file.

-n, --line-number / -N, --no-line-number Toggle line numbers (on by default).

-A NUM / -B NUM / -C NUM Context lines after / before / around matches.

-g, --glob GLOB Include files matching GLOB.

-t, --type TYPE / -T, --type-not TYPE Filter by file type.

-u, --unrestricted Reduce filtering (-u no ignore, -uu +hidden, -uuu +binary).

--hidden Search hidden files and directories.

--no-ignore Don't respect .gitignore/.ignore files.

--json Show results in JSON Lines format.

Examples

$ rg foo

Search for 'foo' in the current directory, recursively.

$ rg -i foo src/

Case-insensitive search restricted to src/.

$ rg -t js foo

Search only JavaScript files.

$ rg -g '*.ts' foo

Search files matching a glob.

Notes

Recursive and .gitignore-aware by default, unlike grep. Use -u/-uu/-uuu to progressively disable that filtering.

See Also

grep, find, egrep