Use ack to search pattern

Normally I use find, xargs and grep to search pattern on source code (besides cscope):

find . -type f | xargs grep pattern

But it is not efficient mainly because it will search on all binary file and it will search on .cvs, .svn, .git directory.

A good alternative it the “ack” program:

On Ubuntu you can just install ack-grep package:
sudo apt-get install ack-grep


$ ack-grep mxc-mmc
45:#define DRIVER_NAME "mxc-mmc"

546:    _REGISTER_CLOCK("mxc-mmc.0", NULL, sdhc1_clk)
547:    _REGISTER_CLOCK("mxc-mmc.1", NULL, sdhc2_clk)

274:    .name = "mxc-mmc",
281:    .name = "mxc-mmc",

369:       .name           = "mxc-mmc",
400:       .name           = "mxc-mmc",

638:    _REGISTER_CLOCK("mxc-mmc.0", NULL, sdhc1_clk)
639:    _REGISTER_CLOCK("mxc-mmc.1", NULL, sdhc2_clk)
640:    _REGISTER_CLOCK("mxc-mmc.2", NULL, sdhc3_clk)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s