How to run a linux command in a loop?

Execute a command multiple times in linux

Running a Linux command multiple times

Sometimes there is a need to run a Linux command multiple times without writing a shell script. For those times you can easily use the following snippet which is similar to how you would do in any programming language. It’s basically a For Loop which iterates through the command and number of times.

for ((n=0;n<10;n++)); do php deleteduplicates.php;
Delete Duplicate Posts and Run command 10 times

in this case I have script name deleteduplicate.php which is a PHP script that I am running for 10 times.  you can just change the number to make it run more or less based on the input. I like this approach because it is readable and doesn’t need any addition program to be installed.


Leave A Comment