Boise, Idaho
Or Remote

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

3 Responses so far.

  1. Andy Lester says:

    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

  2. Jim says:

    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

  3. Scott Stanger says:

    For those Debian / Ubuntu users out there, like myself, you can issue this command to install ack-grep as “ack” instead of “ack-grep”:

    sudo dpkg-divert --local --divert /usr/bin/ack --rename --add /usr/bin/ack-grep

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>