LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

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 search.
-n
Show line numbers.
-l
Print only names of files with matches.
-c
Print only a count of matching lines per file.
-v
Invert match (select non-matching lines).
-w
Match whole words only.
-E
Use extended regular expressions (same as egrep).
-P
Use Perl-compatible regular expressions.
--color WHEN
Colorize matches: auto, always, or never.
--exclude-dir DIR
Skip directory.
--include GLOB
Search only files matching pattern.
--exclude GLOB
Skip 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)

Copied to clipboard
Kai