LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 12-07-2012, 10:56 PM   #1
coryjsanders
LQ Newbie
 
Registered: Apr 2010
Location: Phoenix
Posts: 12

Rep: Reputation: 0
copy file and rename n times in succession


I have this:
#!/bin/bash
#copies named iax modem and saves in ensuing order

cp /etc/iaxmodem/iaxmodem-cfg.ttyIAX20 /etc/iaxmodem/iaxmodem-cfg.ttyIAX21

But would like to create the contents of iaxmodem-cfg.ttyIAX20 n more times and name 22, 23 24, etc
 
Old 12-07-2012, 11:31 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Use a loop:
Code:
for c in {22..28}
do
  cp /etc/iaxmodem/iaxmodem-cfg.ttyIAX20 /etc/iaxmodem/iaxmodem-cfg.ttyIAX$c
done
 
Old 12-08-2012, 12:06 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Or alternatively you can use:
Code:
#!/bin/bash
echo -n "Enter how many times: "; read times
n=20
while [ $n -le $times ]
do
cp  /etc/iaxmodem/iaxmodem-cfg.ttyIAX /etc/iaxmodem/iaxmodem-cfg.ttyIAX$n
n=$((n+1))
done
 
  


Reply


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
bash script to copy rename files dunstable Linux - Newbie 4 10-08-2012 10:53 AM
Bash copy script by times driftux Programming 11 09-23-2012 01:36 AM
Get first file of directory then copy to other directory andd rename the file Faye Linux - Software 4 01-30-2011 09:16 AM
Guide me for copy and rename commands Ye Myint Linux - Newbie 7 11-14-2008 07:27 AM
how to rename a file and copy a file in a shell zach014 Linux - Newbie 6 11-23-2006 09:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:27 AM.

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