Logo

Armand.nz

Home / About / Linkedin / Github

ag the Silver Searcher and ack to search for code and keywords in files

#tools #linux |

ag and ack are search tools designed for code. Find words in files in a directory. It’s built to be a replacement for grep with higher speed and more options

ag aka The Silver Searcher is significantly faster and should be used as a drop in replacement for ack

Yeah, ag and ack do the job fine for me But the internet insist ag orders of magnitude faster than ack

Some actual comparisons and analysis here:

Install ag

The ack search tool can be used on any Perl-supported platform. We use its main package, ack-grep, to install it.

# macos
$ brew install the_silver_searcher
# Debian, Ubuntu, etc
$ sudo apt-get install silversearcher-ag
# Fedora
$ sudo dnf install the_silver_searcher
# On RHEL
$ sudo yum install epel-release.noarch the_silver_searcher
# Arch
$ sudo pacman -S the_silver_searcher
# Suse
$ sudo  zypper install the_silver_searcher

Install Ack

The ack search tool can be used on any Perl-supported platform. We use its main package, ack-grep, to install it.

# macos
$ brew install ack
# Debian, Ubuntu, etc
$ sudo apt-get install ack-grep    
# On RHEL, CentOS, Fedora, Rocky etc
$ sudo yum install ack-grep        
# Arch
$ sudo pacman -S ack-grep
# Suse
$ sudo zypper install ack-grep

Finding keywords and string Pattern variations in files inside a directory

We can demonstrate the string pattern search ability of ack through a source code directory, since it is thought to be source-code oriented.

  1. Enter the Root Directory where you want to start your search from and run ag [search string] or ack [search string]

For example, using ag

cd armsultan.github.io/
ag armand

ag armand
CNAME
1:www.armand.nz

_config.yml
1:name: "ARMAND.NZ"
2:description: "Armand's blog, mostly TIL stuff as a Soltutions Engineer"

and with ack

cd armsultan.github.io/
ack armand

CNAME
1:www.armand.nz
comments powered byDisqus

Copyright © Armand