linux find with exec 命令永远不会结束

标签 linux find infinite-loop

这是我正在调用的命令:

find / -name zad1.sh -size -50M -mtime -1 -exec grep "do" {} \;

然后它回显正确的两行:

do
done

但是,它会继续做某事并且永不停止。我必须手动执行 Ctrl+C 终止进程。谁能向我解释这里发生了什么? 附言我是类 Unix 系统的新手。(我在 Cygwin 上工作)

最佳答案

你必须添加-quit选项;来自联机帮助页:

-quit  Exit immediately.  No child processes will be left running,  but
          no  more  paths specified on the command line will be processed.
          For example, find /tmp/foo /tmp/bar -print -quit will print only
          /tmp/foo.   Any  command  lines  which  have  been built up with
          -execdir ... {} + will be invoked before find exits.   The  exit
          status may or may not be zero, depending on whether an error has
          already occurred.

附言。将“做”改为“做”;双引号内插字符串,do 是 bash 的关键字。

关于linux find with exec 命令永远不会结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36102506/

相关文章:

c++ - 如何修复简单 C++ 函数中的无限循环?

reactjs - React Hooks 无限循环与数组

c - open() 不设置 O_CLOEXEcflags

linux - 在 Linux 中匹配精确的单词

c++ - IPC Unix消息队列线程安全吗?

c# - 从 C# 4.0 中的元组列表中查找和删除元组

jquery - Flexslider无限循环不起作用

c - 如何在不创建所述文件副本的情况下执行 C 程序?

regex - 如何使用带有正则表达式的find,-exec,grep和sed替换部分文本行?

linux - “Sed”无法处理具有多个参数的 'find' 结果