Shopean1951 Shopean1951 - 5 months ago 28
Bash Question

Linux - Do a command repeatedly for a certain length of time

I know what the command watch -n does. I would like to do something like the following:

watch -n 5 "ls" //Do this for 30 minutes, then stop.

Essentially I want to repeat a command every 5 seconds, then stop after 30 minutes has passed. I'm missing the stop 30 minutes part. What command should I use to achieve this?



Use timeout:

timeout 1800 watch -n 5 "ls"