How To Write Infinite Loop in Bash

This is how you create an infinite loop in bash to run a piece of code infinitely at defined intervals.

while [ 1 ]
# Your code goes here

# Modify sleep time (in seconds) as needed below
sleep 2

I needed such code to monitor the size of a file every 2 seconds.


About SoCRaT

Systems Engineer, OSS & Linux Geek
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s