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.
With ack2, it seems you can't use holygeek's solution.
Here's how I'd do it using
-v
and-x
:More generally,
'test'
can be a regex for dirs to excludeIn recent versions of ack, you can use regular expressions with
--ignore-dir
.From this thread:
GitHub link: https://github.com/petdance/ack2/issues/42
Sadly, I think this only supports matching the base directory name, not the full path.
For instance, you cannot match a path like
".*/docs/generated/.*"
with it.For that, see the (still open) GitHub issue 291.
Use the undocumented option "--invert-file-match" (ack version on my system: 1.96):
Well, it is sort of documented:
It is not documented in its perldoc.
In the interest of folks using a pre-1.96 version of ack (like me), you can use regex look around to do this. Here's an example:
This will search the
text-pattern
in allJava
files recursively (from .) that DO NOT have the wordstest
ortarget
in their path.