Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-09-2008, 08:25 PM   #1
LQ Newbie
Registered: Aug 2005
Location: Lilburn, Georgia
Distribution: Linux Red Hat 7.3 /Solaris 8
Posts: 15

Rep: Reputation: 0
How does one make an intentional loop?

Hello everyone,

I'm very new to BASH programming and can't find an example of how to make a loop that runs forever on purpose -I'm finding examples of people trying to stop their perpetual loop -only.

What I want to write is a script that copies files to a directory, then deletes those files -over and over again, until I hit Ctrl + C

I'm working in Linux Red Hat 7.2.
Old 06-09-2008, 08:32 PM   #2
Senior Member
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
There are several guides to scripting in bash on the Internet. Here is one.
Old 06-09-2008, 08:32 PM   #3
LQ Guru
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Linux Mint 17, Debian 8
Posts: 7,863

Rep: Reputation: 311Reputation: 311Reputation: 311Reputation: 311
You can create an infinite loop by using a while statement where the test is never false. For example:

set i 0
while {$i<1}  {
  cp some files to a directory
  rm some files in a directory
Steve Stites
Old 06-09-2008, 08:35 PM   #4
Registered: Feb 2007
Distribution: slackware,gentoo,ubuntu
Posts: 50

Rep: Reputation: 17
while : ; do cp /directory1/* /directory2/; rm /directory2/*; done

or, to include directories and add a little force:
while : ; do cp -R /directory1/* /directory2/; rm -rf /directory2/*; done

while true: ; do cp /directory1/* /directory2/; rm /directory2/*; done
Old 06-10-2008, 03:03 AM   #5
LQ Newbie
Registered: Aug 2005
Location: Lilburn, Georgia
Distribution: Linux Red Hat 7.3 /Solaris 8
Posts: 15

Original Poster
Rep: Reputation: 0
Thank you guys; I didn't realize that it was such a simple thing to accomplish.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: WMF vulnerability actually intentional? LXer Syndicated Linux News 0 01-13-2006 08:01 PM
Accidental or Intentional Restart? MBH Slackware 1 09-17-2005 07:04 AM
Intentional packet dropping - how can I do this? sokar Linux - Networking 1 04-12-2004 12:06 AM
never ending loop on make jods Linux - Software 1 04-02-2004 03:02 PM
Make Loop notsoevil Linux From Scratch 1 02-11-2002 02:51 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:03 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration