more powerful grep – ack

2010-05-26 218 words 2 mins read

For last couple of days, I have been using ack instead of grep. Here is description of ack:

Ack is designed as a replacement for grep.

There are couple of reasons I am using ack. First and foremost being it does not require a filename. So, for seaching amit in all files recursively under the current directory I can simply use

ack amit

More reasons to use ack:

It supports pager option and there can be a rc file that can be used to define the default options that needs to be used with ack. Here is the contents of my $HOME/.ackrc file.

–pager=most

–color

–sort-files

-u

-H

–context=3

–all

SO, basically when I do the search, the output is piped to most command and there are 3 context lines displayed for the search. The filename too is displayed for the search result and the output is colored. <span style="background-color: #ffffff;">There are other options used in the rc file, that you can see in the man page for ack.

Now if I had to do that with grep, I would need a function for grep or an alias but this is much cleaner. Ain&#8217;t it. What do you think, leave a comment to tell me.

You need to install ack with the following command:

sudo yum install ack


Tags: ack grep search

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it