LinuxCommandLibrary

rg

Fast recursive text search with smart defaults

TLDR

Search for a pattern in current directory

$ rg "[pattern]"
copy
Search in specific files or directories
$ rg "[pattern]" [path]
copy
Search case-insensitively
$ rg -i "[pattern]"
copy
Search for whole words only
$ rg -w "[pattern]"
copy
Show line numbers with matches
$ rg -n "[pattern]"
copy
Show context lines around matches
$ rg -C [3] "[pattern]"
copy
Search specific file types
$ rg -t [py] "[pattern]"
copy
Search hidden files and directories
$ rg --hidden "[pattern]"
copy
List files containing matches (no content)
$ rg -l "[pattern]"
copy
Count matches per file
$ rg -c "[pattern]"
copy

SYNOPSIS

rg [options] pattern [path...]

DESCRIPTION

rg (ripgrep) is a fast, recursive grep alternative that respects gitignore rules by default. It searches directories for regex patterns, automatically skipping hidden files, binary files, and ignored paths.
Ripgrep uses Rust's regex engine for speed and supports most Perl-compatible regex syntax. It's designed for searching codebases, automatically detecting and skipping binary files and respecting .gitignore patterns.
Multiple patterns can be specified with -e. File type filtering uses built-in definitions (use rg --type-list to see available types). Custom globs with -g provide flexible include/exclude patterns.
Output is colorized by default when writing to a terminal. Use --color=never for scripts or --color=always for piping to pagers.

PARAMETERS

-i, --ignore-case

Case-insensitive search
-S, --smart-case
Case-insensitive unless pattern has uppercase
-w, --word-regexp
Match whole words only
-x, --line-regexp
Match whole lines only
-c, --count
Show count of matches per file
-l, --files-with-matches
Show only filenames with matches
-L, --files-without-match
Show only filenames without matches
-n, --line-number
Show line numbers (default when terminal)
-H, --with-filename
Show filename with matches
-A num, --after-context
Show num lines after match
-B num, --before-context
Show num lines before match
-C num, --context
Show num lines before and after match
-t type, --type
Search only files of specified type
-T type, --type-not
Exclude files of specified type
-g glob, --glob
Include/exclude files matching glob
--hidden
Search hidden files and directories
-u, --unrestricted
Reduce filtering (repeatable: -uu, -uuu)
-F, --fixed-strings
Treat pattern as literal string
-e pattern
Specify pattern (allows multiple)
-r replacement, --replace
Replace matches with text
-o, --only-matching
Show only matched parts

CAVEATS

By default, ripgrep skips hidden files, gitignored files, and binary files. Use --hidden, --no-ignore, or -u to search more comprehensively.
Ripgrep uses Rust regex syntax, which differs slightly from PCRE. Some advanced features like backreferences are not supported.
For very large result sets, consider -l (files only) or -c (counts) to reduce output volume.

HISTORY

Ripgrep was created by Andrew Gallant (BurntSushi) and first released in 2016. Written in Rust, it combines the usability of The Silver Searcher (ag) with the raw speed of GNU grep, while adding gitignore support. It has become one of the most popular grep alternatives.

SEE ALSO

grep(1), ag(1), ack(1), git-grep(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community