ripgrep — fast grep
💬 "ripgrep command"
ripgrep (rg) is an ultra-fast text search tool that replaces grep. It operates with multithreading, searching instantly even in large codebases.
By default, it respects .gitignore, so it automatically skips directories like node_modules.
- Concept: Searches text patterns in files at ultra-high speed.
- grep replacement: Performs the same pattern search much faster.
- .gitignore respect: Automatically excludes ignored targets.
- Multithreading: Utilizes CPU cores to increase search speed.
Installation and Download
Install ripgrep using a package manager or cargo.
| Environment | Command |
|---|---|
| Ubuntu / Debian | sudo apt install ripgrep |
| Fedora / RHEL | sudo dnf install ripgrep |
| Arch | sudo pacman -S ripgrep |
| macOS (brew) | brew install ripgrep |
| Rust cargo | cargo install ripgrep |
| Binary download | github.com/BurntSushi/ripgrep/releases |
Verify the installation with rg --version. It uses a command structure very similar to grep.
Commonly Used Options
| Option | Description |
|---|---|
| -i | Ignores case |
| -n | Displays line numbers |
| -w | Matches only whole words |
| -t ext | Searches only files with specific extensions |
| --type-add | Adds custom file types |
3 Essential Command Combinations
rg -n "TODO" src/— Find TODO locations in sourcerg -i error /var/log/nginx— Search for error keywords in logs (ignoring case)rg -t py "import os"— Search for import os in Python files
💬 "Show me an example of finding errors in logs on a real server"
I've organized the common situations on a production server in order.
Step 1 · Verify Installation
Check if installed.
rg --version || sudo apt install -y ripgrep
Step 2 · Search for keywords in code
Find specific function calls in source code.
rg -n "handle_request" /var/www/html/src
Step 3 · Search for errors in logs
Find error patterns in log files.
rg -i "error|fail" /var/log/nginx/error.log
Live Execution Example
This is the result of searching for function call locations in source code using ripgrep. It quickly outputs with line numbers.
!ripgrep command execution result
Production server
In practice, here's how it's used
1. Finding specific values in configuration
Situation — Find the timeout value in nginx configuration.
rg -n "timeout" /etc/nginx/
Result — Lines related to timeout are displayed with line numbers.
Tip — With the -n option, you can jump directly to the line.
2. Checking dependencies
Situation — See where a specific library is used in the project.
rg -t py "import requests"
Result — A list of files containing import requests is displayed.
Tip — Filter file types with the -t option.
Live Execution Example
This is the result of searching for error patterns in log files.
!ripgrep command execution result 2
Production server
Important Notes
- ripgrep by default excludes hidden files and .gitignore targets. To include them, use --hidden --no-ignore.
- It skips binary files by default.
- Instead of grep's -r option, it searches recursively by default.
- In large single files, it uses mmap, so memory usage may increase.
Source (HTML): https://games.aidebatehub.com/programs/linux/modern/ripgrep.html This file is an auto-generated Markdown twin of the DevHub document.
AI Knowledge Hub
Visitor Comments