Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
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.


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

share|improve this question
See also this, this, this, ... – grawity Nov 30 '11 at 0:26
up vote 3 down vote accepted

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.

share|improve this answer
In ack2 instead of the -G (which has been removed) you can do: ack -g '\.h$' | ack -x '#define' – jondro Mar 4 '14 at 11:51

You must log in to answer this question.

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