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:
http://betterthangrep.com/

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

Example:

$ ack-grep mxc-mmc
drivers/mmc/host/mxcmmc.c
45:#define DRIVER_NAME "mxc-mmc"

arch/arm/mach-mx3/clock.c
546:    _REGISTER_CLOCK("mxc-mmc.0", NULL, sdhc1_clk)
547:    _REGISTER_CLOCK("mxc-mmc.1", NULL, sdhc2_clk)

arch/arm/mach-mx3/devices.c
274:    .name = "mxc-mmc",
281:    .name = "mxc-mmc",

arch/arm/mach-mx2/devices.c
369:       .name           = "mxc-mmc",
400:       .name           = "mxc-mmc",

arch/arm/mach-mx2/clock_imx27.c
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)
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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