Tech Reflect
  • Home
  • About This Site
  • Contact me
  • Search Icon
Simple repeating command-line command

Simple repeating command-line command

2018-03-19

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

geeky, macOS tips

Post navigation

NEXT
Quick open files of a certain type
PREVIOUS
Flow control in bash
Comments are closed.

Get Monthly Updates

Recent Posts

  • Inserting random email sigs in Mail on iOS
  • Keep Instagram open to finish posting…
  • How I predicted the rise of Twitter, barely used it, and amassed 35,000 followers
  • Apple Books 2022, in pictures
  • Killing one bird with two-and-a-half stones in Mac OS X Mail

Categories

  • analog (1)
  • apple career (12)
  • apple inside (19)
  • apple stories (20)
  • bertrand serlet (3)
  • bugs (3)
  • essays (15)
  • geeky (21)
  • interviews (4)
  • iOS tips (4)
  • Mac OS X (7)
  • macOS tips (36)
  • personal (8)
  • predictions (1)
  • products (5)
  • prototypes (6)
  • scott forstall (7)
  • scripting (2)
  • siri (2)
  • steve jobs (16)
  • tim cook (1)
  • workplace (15)

Get Monthly Updates

About cricket


Me with Guiness the owl

25 years in tech. I like to write manifestos. I like to offer interesting tips. I like making fun of things. Everyone copes differently.

My Other Blogs

  • Free Range Parrots
  • Plucky Tree (personal)
© 2025   All Rights Reserved.