3
ack "#define" 

will recurse into subdirs and find files that contain #define. But I wanted to limit the search to *.h files, so I tried

ack "#define" *.h

and it doesn't recurse anymore. The only results come from files in the working directory.

Version:

ack 1.96 Running under Perl 5.14.2 at /usr/bin/perl

sashang
  • 330
  • 1
  • 9
  • See also [this](http://superuser.com/q/97910/1686), [this](http://superuser.com/q/332442/1686), [this](http://superuser.com/q/246061/1686), ... – u1686_grawity Nov 30 '11 at 00:26

1 Answers1

4

The wildcard *.h is expanded by your shell, and ack only receives individual files as its arguments – it doesn't have anywhere to recurse to.

To avoid this, specify the wildcard inside single or double quotes, but ack likely won't recognize it as a wildcard: ack "#define" "*.h".

A better option is to use --hh to only include header files (see --help type), or -G '\.h$' to only include files matching the specified Perl regex.

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • 1
    In ack2 instead of the -G (which has been removed) you can do: ack -g '\.h$' | ack -x '#define' – jondro Mar 04 '14 at 11:51