Skip to content

ripgrep

Installation

emerge --ask sys-apps/ripgrep sys-apps/ripgrep-all
apt install ripgrep
apt install ripgrep
git clone https://github.com/BurntSushi/ripgrep
cd ripgrep
cargo build --release
RUSTFLAGS="-C target-cpu=native" cargo build --release --features 'simd-accel'
cargo build --release --features 'pcre2'
cargo test --all

Set colors for matching in .bashrc

alias rg="rg --colors 'match:none' \
    --colors 'match:bg:0x33,0x66,0xFF' \
    --colors 'match:fg:white' \
    --colors 'match:style:bold'"

Color Examples

rg --color=always \
    --heading --colors 'line:bg:yellow' \
    --colors 'match:fg:white' \
    --colors 'line:bg:68,71,155' \
    --colors 'match:bg:magenta' foo
rg --color=always \
    --heading \
    --colors 'line:fg:white' \
    --colors 'match:fg:white' \
    --colors 'line:bg:68,71,155' \
    --colors 'match:bg:magenta' \
    --colors 'line:bg:magenta'  ┬┤foo
rg --colors 'match:bg:1,12,155'
rg --colors 'match:bg:1,12,155' \
    --colors 'match:fg:68,71,90'
rg --colors 'match:fg:magenta' --colors 'line:bg:yellow' foo.

Very fast history search with Ripgrep

rh() { rg "$1" ~/.bash_history }

List matching files only

rg -l clap  

Files Without a Match

rg --files-without-match '\b(var|let|const)\b'

Use -v to filter out all matches so that only non-matches are left.

rg 'bar' | rg -v 'foobar'

Displays built-in available types and their corresponding globs

rg --type-list  

Only search in .sh files, -g can be used mulitple tiomes

rg -g '*.shj' clap  

Search in all files excempt .sh files, -g can be used mulitple tiomes

 rg -g '!*.sh' clap 

The following command restricts the search for the pattern key to json files only.

rg key -t json

File separator

rg wuseman --field-match-separator ': Match -> '

Path separator

rg wuseman --path-separator '/'

Find filees that match our string

rg --files-with-matches bash
rg --files-without-match bash

No filename

rg -I 
rg --json 
rg --no-line-number
rg -m 5 file

PAath depth

rg --max-depth 0

Show all supported file types and their corresponding globs.

rg --type-list

Threads (default 20)

rg -t 20 

Show stats

rg --stats

Search in hidden files and folders

rg --hidden

Search in zip files

  • Supported: gzip, bzip2, xz, LZ4, LZMA, Brotli and Zstd
    rg -z
    

Show only match

rg -o foo . 

Sort by

rg --sort none      (Default) Do not sort results. Fastest. Can be multi-threaded.
rg --sort path      Sort by file path. Always single-threaded.
rg --sort modified  Sort by the last modified time on a file. Always single-threaded.
rg --sort accessed  Sort by the last accessed time on a file. Always single-threaded.
rg --sort created   Sort by the creation time on a file. Always single-threaded.

Sort by descending order

rg --sortr none      (Default) Do not sort results. Fastest. Can be multi-threaded.
rg --sortr path      Sort by file path. Always single-threaded.
rg --sortr modified  Sort by the last modified time on a file. Always single-threaded.
rg --sortr accessed  Sort by the last accessed time on a file. Always single-threaded.
rg --sortr created   Sort by the creation time on a file. Always single-threaded.

  • Comments are closed on this article!

Last update: December 7, 2022 03:34:30