简体   繁体   English

Unix查找命令目录提示

[英]Unix find command directory hints

I am an active user of the find command, similar to the below format: 我是find命令的活跃用户,类似于以下格式:

find . -name '*servername*' -exec zgrep -l 'identifier'  {} \;

Suppose I have a hint that the target file may be in directory named abc, is it possible in find command or any of its combinations to accept hints? 假设我有一个提示,目标文件可能在名为abc的目录中,是否可以在find命令或其任何组合中接受提示?

For example, if the search first searches in subdirectories named abc there are more chances to find the results, and I can break the search operation if needed. 例如,如果搜索首先在名为abc的子目录中搜索,则有更多机会找到结果,并且如果需要,我可以中断搜索操作。

I am looking for some similar command: 我正在寻找一些类似的命令:

find --hint dir1|pattern1 . -name '*servername*' -exec zgrep -l 'identifier'  {} \;

Perhaps this is what you want: 也许这就是您想要的:

find $(find . -type d -name abc
      ) -name '*servername*' -exec zgrep -l 'identifier' {} +

Demo: 演示:

$ mkdir /tmp/demo
$ cd /tmp/demo
$ mkdir -p a/b/abc 
$ echo identifier | gzip > a/b/abc/one_servername.gz
$ find $(find . -type d -name abc
        ) -name '*servername*'-exec zgrep -l 'identifier' {} +
./a/b/abc/one_servername.gz

您可以在find中使用多个搜索目录,它将按提供的顺序在其中搜索:

find dir1 dir2 dir3 -name '*servername*' -exec zgrep -l 'identifier'  {} \;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM