The Silver Searcher, a better UNIX search tool
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:
Benefits of ag
- Focus on usability and cleanliness with improved output.
- Already packaged or directly available in most unix platforms: Linux, BSD, MacOS.
- Short command, just type two letters that are located in the home row on your keyboard.
- Fast. Though I haven't found any conclusive benchmark which compares all the tools (and everyone claims that their tool is faster). I don't care. Sometimes typing an extra word takes longer that the search itself.
- Editor integration available for Vim, Emacs, and Sublime Text.
- It supports many of the same grep command line options, so you don't need to learn new flags.
Some key usability features of ag compared to grep
- Smart case search; no more
- Recursive search is the default; no more
- No need to specify search path, it searches the current directory by default; no more
- Supports regexps by default; no more
- Filtering by filename of file extension: no more
grep -r <string> | grep.
- By default it uses ignores VCS files (.gitignore, .hgignore, .svnignore) to skip searching those paths and search faster.
Smart case search
The smart case search feature requires some detailed explanation:
- If your search query is an all small caps query, it does a case insensitive search.
- If your search query is contains any upper caps letter, it searches case sensitive for that
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
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
A few useful examples:
Basic search, search for all instances of
require in your current repo:
Filter by file extension or file name (using
ag -G .markdown dnsimple
Regular expresion search:
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
You can learn more about
ag in its official github repository.
Jacobo García López de Araujo
Devops, infrastructure, urban cyclist, music nerd.
We think domain management should be easy.
That's why we continue building DNSimple.
How We Work as a Remote Team
Inspired by a recent blog post from Travis CI, I'd like to share details about how DNSimple team members work together without offices.
Using time tracking to improve your remote working habits
What we learned, individually, from our collective time tracking experiment.