ripgrep
A fast grep tool #
- tags
- Rust
ripgrep is a line-oriented search tool that recursively searches the current directory for a regex pattern. Written in Rust language and amazingly fast.
Experience #
Used it in helm-rg package in Emacs, works like magic
Command #
# ripgrep --type-list
# or
rg --type-list
options #
-g (–glob) #
Process all glob patterns given with the -g/–glob flag case insensitively. This effectively treats -g/–glob as –iglob. This flag can be disabled with –no-glob-case-insensitive.
file1.txt
File2.txt
file3.TXT
dir1/File4.txt
dir2/file5.TXT
Case-sensitive search (Default behavior):
rg -g '*.txt'
-t (–type) #
Do not search files matching TYPE. Multiple -T/–type-not flags may be provided. Use the –type-list flag to list all available types.
-tis used to search specific file types. For example, if you only want to search through Python files:rg -t py "import os"This command will search for the string “import os” but only within Python files in the current directory and all subdirectories.
-Tis used to exclude certain file types from the search. For example, if you want to search for a string but not within HTML files:rg -T html "search_string"This command will search for “search_string” in all files in the current directory and subdirectories, excluding HTML files.
Examples #
ignore case #
# in a file
rg -i "Error" /var/log/syslog
# current directory
rg -i "Error"
with ^ and $ #
rg '^check.*you$' /opt/homebrew/Cellar -tpy