Ripgrep is a recursive line-oriented search tool. Aims to be a faster alternative to grep. By default, ripgrep will respect gitignore rules and automatically skip hidden files/directories and binary files.
# ----------------------------------------------------------------------
# Usage:
# ----------------------------------------------------------------------
# Recursively search current directory for a pattern (regex):
rg <pattern>
# Recursively search for a pattern in a file or directory:
rg <pattern> <path/to/file_or_directory>
# Search for a literal string pattern:
rg <[-F|--fixed-strings]> -# <string>
# Include hidden files and entries listed in .gitignore:
rg <[-.|--hidden]> --no-ignore <pattern>
# Only search the files matching the glob pattern(s) (e.g. README.*, use !filename_pattern to exclude instead):
rg <pattern> <[-g|--glob]> '<filename_glob_pattern>'
# Recursively list filenames in the current directory and highlight ones that match a pattern:
rg --files | rg <[--passthru|--passthrough]> <pattern>
# Only list matched files (useful when piping to other commands):
rg <[-l|--files-with-matches]> <pattern>
# Show lines that do not match the pattern:
rg <[-v|--invert-match]> <pattern>
# ----------------------------------------------------------------------
# Examples
# ----------------------------------------------------------------------
# Recursively search current directory for a pattern (regex):
rg 'TODO|FIXME'
# Recursively search for a pattern in a file or directory:
rg 'connectionString' ./src
# Search for a literal string pattern:
rg --fixed-strings 'https://api.example.com/v1/users'
# Include hidden files and entries listed in .gitignore:
rg --hidden --no-ignore 'DATABASE_URL'
# Only search files matching the glob pattern(s):
rg 'installation' --glob 'README.*'
# Exclude files matching a glob pattern:
rg 'password' --glob '!package-lock.json'
# Recursively list filenames in the current directory and highlight ones that match a pattern:
rg --files | rg --passthru 'README'
# Only list matched files (useful when piping to other commands):
rg --files-with-matches 'TODO'
# Show lines that do not match the pattern:
rg --invert-match '^#'