【发布时间】:2017-02-28 05:32:00
【问题描述】:
我知道命令 watch -n 的作用。我想做类似以下的事情:
watch -n 5 "ls" //Do this for 30 minutes, then stop.
基本上我想每 5 秒重复一次命令,然后在 30 分钟后停止。我错过了停止 30 分钟的部分。我应该使用什么命令来实现这一点?
谢谢。
【问题讨论】:
标签: linux bash shell ubuntu centos
我知道命令 watch -n 的作用。我想做类似以下的事情:
watch -n 5 "ls" //Do this for 30 minutes, then stop.
基本上我想每 5 秒重复一次命令,然后在 30 分钟后停止。我错过了停止 30 分钟的部分。我应该使用什么命令来实现这一点?
谢谢。
【问题讨论】:
标签: linux bash shell ubuntu centos
使用超时:
timeout 1800 watch -n 5 "ls"
【讨论】:
您可以使用 timeout 命令,它是 coreutils 的一部分,类似于:
timeout 30m watch -n 5 "ls"
【讨论】:
timeout 有多个版本。如果您没有最新的 GNU Coreutils,语法和选项可能会有所不同。