问题描述
我的文件夹结构如下:
/app
/app/data
...
/app/secondary
/app/secondary/data
我想要递归搜索 / app
,包括 / app / data
。我不想搜索 / app / secondary / data
。这是我到目前为止所拥有的:
I want to recursively search /app
, including /app/data
. I do not want to search /app/secondary/data
however. This what I have so far:
ack --ignore-dir=data searchtext
ack --ignore-dir=secondary/data searchtext
第一个命令忽略两个目录,第二个命令忽略两个目录。在app文件夹中,我的ack命令应该是什么样的?
The first command is ignoring both directories and the second one is ignoring neither of them. From within the app folder, what should my ack command look like?
推荐答案
此答案适用于先前版本的Ack到2,请参见版本。
This answer is for versions of Ack prior to 2, see This answer for versions of Ack >=2.
第一个忽略这两个,因为它们都以数据作为子目录,并且默认情况下使用ack搜索子目录。因此它将忽略具有该名称的任何子目录。不幸的是,您的第二种方法也不起作用。
The first one is ignoring both because they both have 'data' as a sub-directory and ack searches sub-dirs by default. So it will ignore any sub-dir with that name. Unfortunately, your second way doesn't work either. This works for me:
ack -a searchtext -G '^(?!.*secondary/data.*).*$'
代替-a来搜索所有文件,请参阅ack-grep --help = types to仅搜索某些文件类型,例如--type = text
Instead of -a to search all files, see ack-grep --help=types to search for only certain file types, eg --type=text
这篇关于ack:仅排除一个目录,但保留所有其他名称相同的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!