I was first introduced to ack when working for a small web agency in the south by a guy called Stuart. I remember him explaining it as “it’s much faster than grep, but that’s because it cheats”. This article will show you how to use ack as well as the useful flags available to speed up your back-end web development.
If you’re on Mac OS X using Homebrew, installation is as easy as
brew install ack
Otherwise, installation is just as easy across other packages, just visit http://beyondgrep.com/install/
Using ack is pretty simple, and super fast. It’s rather useful as it shows the line numbers within the code and you can change how many lines you want to show before and after using the -c flag like so:
ack '\.container' -C 9
The backslash stops the dot from being used as a regular expression, so we’re essentially searching for just ‘.container’. The results are as follows:
➜ resource git:(master) ✗ ack '\.wrapper' -C 9
27- height: 26px;
28- padding-left: 162px;
29- box-sizing: border-box;
30- background-repeat: no-repeat;
31- background-image: url('../img/logo.svg');
34- padding: 55px 0 20px 0;
37- margin: 0 auto;
38- padding: 0 20px;
39- max-width: 1000px;
40- position: relative;
44-/* --- Page --------------------- */
If you’re a new guy taking over someone else’s work and have no idea where anything is, without having anyone to ask, ack will end up being your best friend. Looking for that horrible problematic inline styling on that div tag? Just use ack:
ack '\<div style\=\"margin-top: -27px;\">'
And there it is. No more nasty
!important hacks. I know this has helped me on a number of projects on so many occasions, especially during handovers and the person of interest is off.
If you’re ever looking for something, don’t forget you always have man files. I always forget we have these to look at, it’s just a case of using them and searching for the right keyword to find what you’re looking for. Just use: