【问题标题】:Find especific directory and ignore other查找特定目录并忽略其他
【发布时间】:2015-06-15 13:52:39
【问题描述】:

我需要在一台服务器上找到所有 iplanet,我正在考虑使用以下命令:

find / type d -name https-* |  uniq

但同时我需要忽略一些目录/文件。我一直在尝试使用!,但它并不总是有效。我有这样的命令:

find / type d -name https-* ! -name https-admserv* ! -name conf_bk* ! -name alias* ! -name *db* ! -name ClassCache* |  uniq

我需要忽略这一切。目录admservconf_bkaliastmp 以及文件*.db* 基本上我需要找到这个:

/opt/mw/iplanet/https-daniel.com
/opt/https-daniel1.com
/apps/https-daniel2.com

我只需要找到目录名。我怎么能忽略所有其他的东西?

【问题讨论】:

  • 如果要跳过整个目录,请使用-prune
  • 另外,您应该将所有带有通配符的参数放在引号内,否则通配符将在当前目录中展开。

标签: linux find


【解决方案1】:

使用-prune 避免递归到目录:

find / \( -type d \( -name 'https-admserv*' -o -name 'conf_bk*' -o -name 'alias*' -o -name 'tmp' \) -prune -o -type d -name 'https-*' -print

无需忽略任何文件。您只选择了https-* 目录,因此忽略其他所有内容。

并且没有必要通过管道传递给uniq,因为find 永远不会产生重复项。

【讨论】:

    猜你喜欢
    • 2021-01-23
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 2018-10-17
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 2017-05-10
    相关资源
    最近更新 更多