Search tool – How to use ripgrep?

Installation

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ brew install ripgrep
$ brew install ripgrep
$ brew install ripgrep

Usage

How to search all files in the current directory (and its subdirectories) for a string?

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# Output file path & line number & content
$ rg 'hung-nb'
# Output 2 lines before and after
$ rg 'hung-nb' -C 2
# Output 2 lines after
$ rg 'hung-nb' -A 2
# Output only file path
$ rg -l 'hung-nb'
# Output file path & line number & content $ rg 'hung-nb' # Output 2 lines before and after $ rg 'hung-nb' -C 2 # Output 2 lines after $ rg 'hung-nb' -A 2 # Output only file path $ rg -l 'hung-nb'
# Output file path & line number & content
$ rg 'hung-nb'

# Output 2 lines before and after
$ rg 'hung-nb' -C 2

# Output 2 lines after
$ rg 'hung-nb' -A 2

# Output only file path
$ rg -l 'hung-nb'

How to search specific language files?

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# Javascript files (*.js, *.jsx, and *.vue)
$ rg -t js 'hung-nb'
# Markdown files (*.markdown, *.md, *.mdown, and *.mkdn)
$ rg -t md 'hung-nb'
# Javascript files (*.js, *.jsx, and *.vue) $ rg -t js 'hung-nb' # Markdown files (*.markdown, *.md, *.mdown, and *.mkdn) $ rg -t md 'hung-nb'
# Javascript files (*.js, *.jsx, and *.vue)
$ rg -t js 'hung-nb'

# Markdown files (*.markdown, *.md, *.mdown, and *.mkdn)
$ rg -t md 'hung-nb'

Be the first to comment

Leave a Reply

Your email address will not be published.


*