Turbo charging your command line with ripgrep
Posted on Tuesday, 12th September 2017
In the past few years the command line has made a resurgence in the Windows world. With the .NET Core CLI now a first class citizen and the Linux sub-system for Windows making it easy to run Linux based tools on a Windows machine, it’s clear that Microsoft are keen to boost the profile of the CLI amongst developers.
Yet Windows has always come up short on delivering a powerful grep experience for searching via a command line, this is where a tool like ripgrep can help you.
Having first heard about ripgrep after a conversation on Twitter, I was made aware of the fact that most people are actively using it without knowing it as ripgrep is what powers Visual Studio Code’s search functionality! (see here)
As someone that’s a heavy user of grep in my day-to-day work flow the first thing that blew me away with ripgrep was its blazing fast speed. Having read its benchmarks that it so proudly displays on its GitHub page, at first I was septical - but ripgrep flies on large recursive searches like no other grepping tool I’ve used.
Let’s take a look.
A bit about ripgrep
Written in Rust, ripgrep is a tool that combines the usability of The Silver Searcher (a super fast ack clone) with the raw performance of GNU. In addition, ripgrep also has first class support for Windows, Mac and Linux (available on their GitHub page), so for anyone who regularly works across multiple platforms and is looking to normalise their tool chain then it’s well worth a look.
Some of ripgrep’s features that sold it to me are: - It’s crazily fast at searching large directories - Ripgrep won’t search files already ignored by your .gitignore file (this can easily be overridden when needed). - Ignores binary or hidden files by default - Easy to search specific file types (making it great for searching for functions or references in code files) - Highlights matches in colour - Full unicode support - First class Windows, Mac and Linux support
Let’s take a look at how we can install ripgrep.
If you’re on a Mac using Homebrew then installation is as easy as:
$ brew install ripgrep
- Download the ripgrep executable from their releases page on GitHub
- Put the executable in a familiar location (
- Add the aforementioned tools path to your
Alternatively if you’re using Chocolately then installation is as simple as:
$ choco install ripgrep
$ yum-config-manager --add-repo=https://copr.fedorainfracloud.org/coprs/carlwgeorge/ripgrep/repo/epel-7/carlwgeorge-ripgrep-epel-7.repo
$ yum install ripgrep
Next, let’s take a look at some of the use cases for ripgrep in our day-to-day scenarios.
Recursively search contents of files in current directory, while respecting all
.gitignore files, ignore hidden files and directories and skip binary files:
$ rg hello
Search the contents of
.css files only for the word
foobar using the Type flag (t).
$ rg -thtml -tcss foobar
Or return everything but css files using the Type Not flag (T):
$ rg -Tjs foobar
Returns a list of all .css files
$ rg -g *.css --files
ripgrep has a whole host of other searching options so I’d highly recommend checking out their GitHub page where they reference more examples.
Hopefully this post has given you a taste of how awesome ripgrep is and encouraged you to at least install it and give it a spin. If you’re someone that spends a lot of time on the command line for day to day navigation then having a powerful grepping tool at your disposal and getting into the habit of using it whenever you need to locate a file really does help your work flow.
Now, go forth an grep with insane speed!
Enjoy this post? Don't be a stranger!
Follow me on Twitter at @_josephwoodward and say Hi! I love to learn in the open, meet others in the community and talk Go, software engineering and distributed systems related topics.