ack
this is ack
country
ack
is like grep
.
You can use both commands to search for strings within a file or directory.
But I like ack
more.
Hereās why:
- ack has a simpler, more intuitive syntax.
ackās output is pretty by default.
ack only searches things that make sense to search.
ack
searches recursively out-of-the-box while ignoring binary files, .git, .svn, and other VCS directories by default. It also ignores common backup files created by certain editors.- PROTIP ā In any given directory, run
find . | wc -l
to see everything grep would search, then runack -f | wc -l
to see everything ack would search. I know you didnāt run those commands, but trust me, thereās a big difference and thatās good.
- PROTIP ā In any given directory, run
- ack is portable.
Installing it on Windows, Unix, or Linux isnāt an issue.
ack
is written in Perl, which is its only dependency.
TL;DR I like ack
more becuase it does the same thing grep
does, only with nicer defaults and a simpler syntax.
Say YES to life⦠say YES to ack
.
installation
If youāre on Ubuntu or Debian, install the ack-grep package.
sudo apt-get update |
The executable installs as ack-grep
, but we can tell our system to just respond to ack
.
sudo dpkg-divert --local --divert /usr/bin/ack --rename --add /usr/bin/ack-grep |
If youāre on a Mac and have Homebrew installed, the installation is much more straight-forward.
brew install ack |
Beyond that, visit the offical install page for installation instructions on your particular OS.
examples
While wrapping strings in quotes isnāt necessary, itās encouraged for legibility.
# Find string "foo" in every file in current directory. |
using regular expressions
ack uses Perl regular expressions. Hereās a cheatsheet.
# Find IDs in .css files in current directory |
configurationā .ackrc
Configure ack to do your bidding in a more intelligent way. Here are some suggestions to make life easier. Throw these into your .ackrc config file.
# Ignore node_modules directory |
wrap-up
Iāve replaced using grep
entirely in my workflow. Maybe some cases will arise where I have use grep
again,
and thatās fine.
In the meantime I enjoy using this tool.
There are more advanced options to ack
, but this should get you
started for most of what youāre probably trying to do.
Have fun!
Comments