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

1

1 Answer 1

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.

1
  • 1
    In ack2 instead of the -G (which has been removed) you can do: ack -g '\.h$' | ack -x '#define'
    – jondro
    Mar 4, 2014 at 11:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .