LinuxCommandLibrary

rgrep

Recursive grep through directories

TLDR

Search recursively
$ rgrep "[pattern]" [path]
copy
Case insensitive
$ rgrep -i "[pattern]" [path]
copy
Show line numbers
$ rgrep -n "[pattern]" [path]
copy
List matching files only
$ rgrep -l "[pattern]" [path]
copy
Count matches
$ rgrep -c "[pattern]" [path]
copy
Exclude directory
$ rgrep --exclude-dir=[node_modules] "[pattern]" [path]
copy

SYNOPSIS

rgrep [-i] [-n] [-l] [options] pattern [path]

DESCRIPTION

rgrep is a convenience wrapper equivalent to grep -r, providing recursive text searching through directory trees. It traverses all subdirectories from the specified path, searching file contents for the given pattern using standard grep regular expression syntax.
All standard grep options work with rgrep, including case-insensitive search (-i), line numbers (-n), listing matching files only (-l), and inverted matching (-v). The --exclude-dir and --include flags allow filtering which files and directories are searched, which is important for skipping large directories like node_modules or build output.
On most GNU/Linux systems, rgrep is installed by default as part of the GNU grep package. For better performance on large codebases, consider using ripgrep (rg) which is significantly faster and automatically respects .gitignore rules.

PARAMETERS

-i

Case insensitive.
-n
Show line numbers.
-l
Files only.
-c
Count matches.
-v
Invert match.
-w
Match whole words only.
--exclude-dir DIR
Skip directory.
--include GLOB
Include pattern.
--exclude GLOB
Exclude files matching pattern.

CAVEATS

By default follows symlinks on the command line. May be slow on large trees. Deprecated in GNU grep in favor of grep -r, but still provided for backward compatibility. Consider ripgrep (rg) for better performance on large codebases.

SEE ALSO

grep(1), egrep(1), fgrep(1), rg(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard