Shopean1951
Shopean1951

Reputation: 79

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.

Upvotes: 2

Views: 105

Answers (2)

PaulRM
PaulRM

Reputation: 409

You can use the timeout command, that is part of coreutils, something like:

 timeout 30m watch -n 5 "ls"

Upvotes: 3

Ipor Sircer
Ipor Sircer

Reputation: 3141

Use timeout:

timeout 1800 watch -n 5 "ls" 

Upvotes: 7

Related Questions