Skip to content
Advertisement

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?

Thanks.

Advertisement

Answer

Use timeout:

timeout 1800 watch -n 5 "ls" 
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement