Ripgrep: How to Show Line Numbers

Updated

Learn how to show line and column numbers with ripgrep (rg)

Ripgrep: How to Show Line Numbers

Before we start, make sure you have ripgrep installed on your computer. On a Mac, you can install it with Homebrew:

brew install ripgrep

Good news: in your terminal, ripgrep already shows line numbers by default. Open your terminal, go to your project folder and run a search, and you'll see the number in front of every matching line.

The catch is that ripgrep drops them as soon as you pipe the output into another command or a file. To keep them, add -n (or --line-number):

rg -n "pattern" | head -n 20

Each line now reads file:line:text, so you can see exactly where every match is.

If you also want the exact character position on the line, add --column:

rg --column "pattern"

You'll get two numbers per match, the line and then the column, for example 12:6.

undefined

If you ever want to hide line numbers in the terminal, use a capital -N (--no-line-number).