ack:通过正则表达式从搜索中排除特定目录 [英] ack: Exclude specific directories from search via regex
本文介绍了ack:通过正则表达式从搜索中排除特定目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过带有 ack 的RegEx忽略特定目录?
How do I ignore specific directories via RegEx with ack?
我可以使用-ignore-dir
选项,但这不能让我指定RegEx。我希望能够忽略任何名称中包含 test
或 tests
或更复杂模式的目录。
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.
我还尝试通过
ack -G '(?<!test)' pattern
但这不起作用。它不排除 test
目录。
but this does not work. It does not exclude the test
directories.
推荐答案
使用未公开说明的选项 --invert-file-match(我系统上的ack版本:1.96):
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.
它的perldoc中没有记录。
It is not documented in its perldoc.
这篇关于ack:通过正则表达式从搜索中排除特定目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文