Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
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

share|improve this question
    
See also this, this, this, ... –  grawity Nov 30 '11 at 0:26

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.