linux repeat command x times

Post Reply
mister_v
Posts: 188
Joined: Thu Mar 04, 2010 9:19 pm

linux repeat command x times

Post by mister_v »

Hey,

is there a way to repeat a command several times ?
with out re-typing the command.
chris
Site Admin
Posts: 194
Joined: Mon Jul 21, 2008 9:52 am

Re: linux repeat command x times

Post by chris »

With the up arrow you get the last commands you typed, and press enter to execute it.

If you want to run the same command several times,
you can use for-loop ( in bash)

Code: Select all

for n in {1..3}; do <COMMAND>; done
repeats 3 times


Another option is watch
If you want to repeat a command every x seconds, ideal for monitoring:

Code: Select all

watch -n 10 <COMMAND>
repeats every 10 seconds.
quit with CTRL+C
Post Reply