When comparing The Silver Searcher (Ag) vs Grep, the Slant community recommends The Silver Searcher (Ag) for most people. In the question“What are the best open source tools for searching source code?” The Silver Searcher (Ag) is ranked 1st while Grep is ranked 3rd. The most important reason people chose The Silver Searcher (Ag) is:
It is written in C. It is up to 10 times faster than ack.
Ranked in these QuestionsQuestion Ranking
Pros
Pro Really fast
It is written in C. It is up to 10 times faster than ack.
Pro Simple syntax
Ack-compatible.
Pro Ignores files in .gitignore by default
It ignores file patterns from your .gitignore
, .hgignore
and .ignore
. This can be a bit buggy though.
Pro Supports PCRE RegExp
Supports RegEx like look-ahead/behind (only fixed length lookbehind however).
Pro No need to manage another config file or learn a new config syntax
Everything is managed with command line args, meaning you can store commonly used options through .bashrc
aliases, bash scripts, and/or autocompletion. There is no config file format to learn or extra dotfiles to manage.
Pro Preinstalled on every Unix like system
Pro Searches any text file
Pro Reads from STDIN
You can search the output of any command just by piping into grep
.
Pro Searches multiple files
It is possible to instruct grep to search through multiple files specified on the command line or entire directory trees.
Pro Full PCRE regex support
Pro Fast
Searches through large collections of files well before the expected time.
Cons
Con You have to remember commonly used options and add them as flags everytime
You are not able to define options in a config file as there is none. (You have to use a shell alias or wrapper script to get your default options.)
Con Cannot add custom file types
All file types ag is able to search for are baked into the executable. There is no way to add new ones neither via command line nor via (the not existing) config file. The only way is a pull request on github and waiting for a new release.
Con Hard to filter by file type
Want to search for my_function in PHP files only? find . -name '*.php' -exec grep my_function '{}' ;
Con Multiple, not fully compatible, implementations
The most known 2 are: BSD and GNU implementations which slightly differ in their capabilities and performance.