【问题标题】:search with find command until first match使用 find 命令搜索直到第一个匹配
【发布时间】:2012-10-04 20:10:47
【问题描述】:

我只需要搜索一个可以在任何地方的特定目录有没有办法运行这个命令直到第一次匹配?谢谢! 我现在正在使用

find / -noleaf -name 'experiment' -type d | wc -l

【问题讨论】:

  • 查阅 find 的手册页;这是-quit 选项

标签: bash command find


【解决方案1】:

正如 Rudolf Mühlbauer 提到的,-quit 选项告诉find 退出。手册页示例是
find /tmp/foo /tmp/bar -print -quit
将只打印/tmp/foo

更笼统地说,find 可能是您想要做的错误的工具。见man locate。例如,在我的系统上,
locate experiment | head -3
产生

/usr/lib/tc/experimental.dist
/usr/share/doc/xorg/reference/experimental.html
/usr/share/doc/xorg/reference/experimental.txt

locate -r 'experimental..$' 产生(为简洁起见,剪掉了 6 行)

/usr/src/linux-headers-3.2.0-24-generic/include/config/experimental.h
 (snip)
/usr/src/linux-headers-3.2.0-32-generic/include/config/experimental.h

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-14
    • 1970-01-01
    • 2011-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-22
    相关资源
    最近更新 更多