【问题标题】:Linux find catalogs and print only namesLinux 查找目录并仅打印名称
【发布时间】:2018-05-13 05:48:16
【问题描述】:

我想搜索名称中包含“程序”的目录并在控制台中回显这些名称。我已经写了这个,但是没有用:

find usr -type d -name "program" -exec echo {} 错误是 find: missing argument to `-exec'。

找到 usr -type d -name "program" usr/lib64/libreofice/程序

如何修复我的命令?

【问题讨论】:

    标签: linux shell terminal


    【解决方案1】:

    * 通配符的一些小例子。

    find /my/path -name "*program*"
    

    如果您不使用通配符,它​​将尝试准确查找名为 program 的文件。另外,回显是自动完成的,您不需要exec 命令。

    更新 回答您的评论。您可以通过以下方式获取基本名称(不带路径的名称):

    find . -name "*program*" -exec basename {} \;
    

    【讨论】:

    • 但它返回的名称带有整个路径:xxx/ccc/program 我只想要目录(而不是文件)的名称。
    猜你喜欢
    • 2012-03-24
    • 2023-03-15
    • 2013-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-06
    • 2017-09-28
    相关资源
    最近更新 更多