Why ack is better than grep
There are too many reasons to list. But I will list one which is very, very useful.
The other day I was searching for a specific ID that was defined within a css file. The problem is that there are about 3 dozen css files scattered within this huge project.
The problem: Recursively search *.css files for something.
The grep solution:
$ find . -type f -iname "*.css" -exec grep -H "something" {} \;
The ack solution:
$ ack something -G .\.css
- Posted by Scott Stanger
- Posted in linux
- Aug, 17, 2012
- 3 Comments.
Search High Corral
Categories
- linux (6)
- ubuntu (2)
- ubuntu 12.04 LTS (1)
- useful stuff (2)
I’m glad you like ack, and I hope you’ll like it even more after I tell you that there’s a better way to do that, because ack has you covered.
ack something –css
ack has a concept of filetypes, and it knows about many of them automatically. Try “ack –help-types” to see them all.
You want to search only HTML and CSS files? Got it:
ack something –html –css
You want to search all files except for the PHP files?
ack something –nophp
Thanks for the tip. For noobs like me, it might be as well to mention that the “ack” you are talking about is a Perl module, not a linux utility. In my innocence, I used “apt-get install ack” to install ack and then typed “man ack” to discover that I had got a Japanese script conversion utility! A few minutes head scratching and a bit of googling and all was made clear – I then downloaded ack from cpan.
Thanks again, it’s a very handy utility that I hadn’t heard of before.
Tip: Installation instructions are on
http://betterthangrep.com/install
For those Debian / Ubuntu users out there, like myself, you can issue this command to install ack-grep as “ack” instead of “ack-grep”: