【问题标题】:UNIX Command Line - How to "find" directories using embedded wildcardUNIX 命令行 - 如何使用嵌入式通配符“查找”目录
【发布时间】:2015-06-12 12:23:54
【问题描述】:

我想在名为 "2" 的 UNIX 服务器上查找所有/任何目录,但我只希望它们位于某个目录结构名称 "/home/abc/public_html" 内。

我试过了:

find / -type d -name "/home/abc/public_html/*2"

但我得到了错误

find: 警告:Unix 文件名通常不包含斜杠(尽管 路径名)。

【问题讨论】:

    标签: unix find


    【解决方案1】:

    -a添加条件:

    find . -name '*/home/abc/public_html/*' -a -name '*2'
    

    或者,如 cmets 中所见:

    find / -type d -wholename "*/home/abc/public_html/*2"
    

    因为你得到了错误

    find: 警告:Unix 文件名通常不包含斜杠(尽管 路径名可以)。这意味着 '-name /home/vps/public_html/'' 将 在这个系统上可能一直评估为假。你可能会发现 “-wholename”测试更有用,或者“-samefile”。 或者,如果您使用 GNU grep,您可以使用 'find ... -print0 | grep -FzZ /home/vps/public_html/''。”

    【讨论】:

    • 得到了同样的错误信息“find: warning: Unix 文件名通常不包含斜杠(尽管路径名包含)。这意味着 '-name */home/vps/public_html/*'' will probably evaluate to false all the time on this system. You might find the '-wholename' test more useful, or perhaps '-samefile'. Alternatively, if you are using GNU grep, you could use 'find ... -print0 | grep -FzZ */home/vps/public_html/* ''。”
    • 您正在开发什么操作系统?请参阅unix.stackexchange.com/a/98445/40596,他们提出了一些变化
    • CENTOS 6.6 i686 virtuozzo
    • 如果您按照错误消息中的描述尝试对-wholename 进行相同操作会怎样? find / -type d -wholename "/home/abc/public_html/*2"
    • @H.Ferrence 是的,我明白了。 find / -type d -wholename "/home/abc/public_html/*2" 没有向您返回任何内容,可能是因为我们错过了 *find / -type d -wholename "*/home/abc/public_html/*2" 有什么用?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    • 2014-04-16
    • 1970-01-01
    • 1970-01-01
    • 2011-07-27
    • 2012-04-21
    • 2017-10-19
    相关资源
    最近更新 更多