Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ack: Exclude specific directories from search via regex

Tags:

regex

ack

How do I ignore specific directories via RegEx with ack?

I can use the --ignore-dir option, but this does not let me specify a RegEx. I want to be able to ignore any directory, which has the words test or tests or more complicated patterns in its name.

I also tried a negative lookbehind via

ack -G '(?<!test)' pattern 

but this does not work. It does not exclude the test directories.

like image 225
cschol Avatar asked Dec 29 '11 15:12

cschol


1 Answers

Use the undocumented option "--invert-file-match" (ack version on my system: 1.96):

$ ack pattern -G 'test|tests' --invert-file-match 

Well, it is sort of documented:

$ ack --help|grep invert -v, --invert-match    Invert match: select non-matching lines --invert-file-match   Print/search handle files that do not match -g/-G. 

It is not documented in its perldoc.

like image 68
holygeek Avatar answered Oct 09 '22 16:10

holygeek