27

I've got a list of files that I would like to search for a pattern with ripgrep.

How can this be done?

1 Answer 1

36

ripgrep accepts file paths as arguments. So just pass your files as arguments:

rg pattern file1 file2 ...

If your list is in a file, with one path per line, then use xargs:

xargs -d '\n' -a list-file rg pattern

Or if it's a list generated from find, then:

find ./ ... -print0 | xargs -0 rg pattern
5
  • 2
    Searching only some specific file can be done like find . -iname '*finde_me*.md' -print0 | xargs -0 rg 'search term'
    – Norfeldt
    Aug 7, 2020 at 9:41
  • 10
    In that case, you might as well just use rg 'search term' -g '*finde_me*.md' :-) Aug 7, 2020 at 13:17
  • Nice! Started using ripgrep a couple of weeks ago and it's truly amazing! Learning so much!
    – Norfeldt
    Aug 7, 2020 at 13:31
  • Is there a performance benefit in not using xargs, find, etc? Aug 5, 2022 at 10:00
  • There might be, given that, e.g., find is single threaded and ripgrep is multi-threaded. Why not try both and compare them for your use case? Aug 5, 2022 at 14:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .