Lessons learned from buying, connecting, and operating domains
Free Trial
Learning

The Silver Searcher, a better UNIX search tool

Jacobo García López de Araujo's profile picture Jacobo García López de Araujo

I was introduced to ack by Xavi Noria several years ago. I liked the usability of the tool but I was so accustomed to find and grep that I never got around to learning it. This post is the perfect excuse to change that and learn ack.

While doing my initial ack research I discovered that there's been an onslaught of new search command line tools in the last few years—focusing in both usability and speed. If you're interested in knowing more about the rest of the tools I will just name a few: ag, pt, sift, ripgrep, ucg and gitgrep.

I decided to compromise on ag also known as The Silver Searcher, an ack compatible tool that searches faster. It is opensource (Apache license), written in C, and mantained by Geoff Greer.

Benefits of ag

Some key usability features of ag compared to grep

The smart case search feature requires some detailed explanation:

Example:

ag trusty will search for any reference to trusty: Trusty, TRUSTy, trusty, TrusTy and so on ag Trusty will search and output only references to Trusty. ag TRUSTY this is the same as the previous example.

If you wish to perform strict case insensitive (for lowercase) queries, you just need to use the -i flag.

A few useful examples:

Basic search, search for all instances of require in your current repo:

ag require

Filter by file extension or file name (using -G flag):

ag -G .markdown dnsimple

Regular expresion search:

ag tiny[-_]p

Search compressed files using -z flag:

ag -z -G .zip packed

It parses from stdin (as any good UNIX tool should):

ag --help | ag search

Learn more

You can learn more about ag in its official github repository.

Share on Twitter and Facebook

Jacobo García López de Araujo's profile picture

Jacobo García López de Araujo

Devops, infrastructure, urban cyclist, music nerd.