Tech Reflect

Tech Reflect

Share this post

Tech Reflect
Tech Reflect
Simple repeating command-line command

Simple repeating command-line command

Chris Hynes - cricket's avatar
Chris Hynes - cricket
Mar 20, 2018
∙ Paid

Share this post

Tech Reflect
Tech Reflect
Simple repeating command-line command
Share

Rather than write a script for something you may only need once, there’s an easy way to repeat a series of command-line commands. This works in bash and may in other shells:

while [ 1 ]; do <some command>; <some other command>; sleep <some delay in seconds>; done;

So, for example:

while [ 1 ]; do date; uptime; sleep 10; done;
This will generate:
Mon Mar 19 13:20:30 PDT 2018
13:20 up 1:23, 3 users, load averages: 3.25 3.87 3.51
Mon Mar 19 13:20:40 PDT 2018
13:20 up 1:24, 3 users, load averages: 3.31 3.86 3.51
Mon Mar 19 13:20:50 PDT 2018
13:20 up 1:24, 3 users, load averages: 5.44 4.30 3.67

Just use Ctrl-C to end.

Extra credit

Add a counter so that it runs 10 times only:

for n in $(seq 1 10); do date; uptime; sleep 10; done

Keep reading with a 7-day free trial

Subscribe to Tech Reflect to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Christopher Hynes
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share