ripgrep
rg is a fast recursive search tool. Compared to grep -r it searches the
current directory by default, respects .gitignore, skips hidden files and
binary files, and prints line numbers and filenames out of the box.
Install: apt install ripgrep, brew install ripgrep, or
winget install BurntSushi.ripgrep.MSVC.
Search the current directory recursively
rg 'pattern'
rg 'pattern' /path/to/searchCase-insensitive, whole word, or literal string
rg -i 'pattern' # ignore case
rg -w 'word' # whole word only
rg -F 'a.b(c)' # fixed string, no regexShow context lines
rg -C 3 'pattern' # 3 lines before and after
rg -B 2 -A 5 'pattern'Filter by file type or glob
rg -t py 'pattern' # only Python files
rg -T js 'pattern' # everything except JavaScript
rg -g '*.md' 'pattern' # glob include
rg -g '!node_modules' 'pattern' # glob exclude
rg --type-list # all known typesList files or counts instead of lines
rg -l 'pattern' # filenames that match
rg --files-without-match 'pattern'
rg -c 'pattern' # match count per file
rg -o 'pattern' # print only the matching partSearch for filenames
--files lists the files rg would search. Combine with -g to find by
name:
rg --files # every searchable file
rg --files -g '*report*' # filenames matching a glob
rg --files | rg -i 'report' # or filter the list with a regexInclude what rg skips by default
rg --hidden 'pattern' # also hidden files
rg -u 'pattern' # ignore .gitignore rules
rg -uu 'pattern' # ...and hidden files
rg -uuu 'pattern' # ...and binary filesMultiple patterns, multiline, replacement preview
rg -e 'one' -e 'two'
rg -U 'start.*\n.*end' # multiline
rg 'old' -r 'new' # show output with replacement (does not edit files)Search compressed files
rg -z 'pattern' file.gz-z decompresses gzip, bzip2, xz, lzma, lz4, brotli and zstd single
files on the fly. It does not open .zip or look inside a tarball’s
members. See Search Inside Archives.
See also
- Search Files and Filenames — the task-level hub.
- grep — available everywhere
rgisn’t. - Finding Strings in Files on Windows — PowerShell alternative.