Created
April 28, 2025 17:23
-
-
Save nicolaymh/777b5297b9c2f04b2b1dc4ab58e32b96 to your computer and use it in GitHub Desktop.
A complete guide to install and use ripgrep (rg) for fast and efficient text searches in files and directories.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1: Install ripgrep | |
# First, update your package list to make sure everything is up to date. | |
sudo apt update | |
# Install ripgrep using the package manager. | |
sudo apt install ripgrep | |
# Step 2: Verify installation | |
# Check that ripgrep was installed successfully by running: | |
rg --version | |
# Step 3: Basic Usage of ripgrep | |
# Example 1: Search for a pattern in the current directory. | |
# This searches for "function" in the entire project directory. | |
rg "function" | |
# Example 2: Search for a pattern in a specific file. | |
# This searches for "function" in the file 'example.js'. | |
rg "function" example.js | |
# Example 3: Case-insensitive search. | |
# This searches for "function" without case sensitivity. | |
rg -i "function" | |
# Example 4: Search for whole words only. | |
# This ensures that only exact words are matched, not partial ones. | |
rg -w "function" | |
# Example 5: Show line numbers with the results. | |
# This will show the line numbers in the search results. | |
rg -n "function" | |
# Example 6: Search and show context (lines before and after the match). | |
# This shows 2 lines of context around each result. | |
rg -C 2 "function" | |
# Example 7: Search and replace (output only). | |
# This will show what will be replaced, without actually modifying the files. | |
rg -r 's/old/new/' example.js | |
# Example 8: Search and replace in files (in-place). | |
# This will replace text directly in the files. | |
rg -r 's/old/new/' -l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment