copying same file multiple times with different names


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers copying same file multiple times with different names
# 1  
Old 07-30-2011
copying same file multiple times with different names

hi,

I am copying a file from 1 folder to another in /bin/sh. if the file already exists there, it should get copied as filename1. again if copying next time it shouldget copied as filename2.. , filename3..so on..

The problem is i am able to get uptil filename1.. but how do i know what was the last highest no. it went to , so that next time it is one more than that.

please suggest. Thanks
# 2  
Old 07-30-2011
First suggestion is to change the numbering system.
If you don't expect more than say 9999 versions ever, then number the files filename0001 , filename0002 etc. . Then it is easy to find the highest with:
Code:
ls filename???? | tail -1

... and then derive the next in the sequence.
The problem with the numbering system which has no leading zeros is that filename101 comes before filename11 in the normal "ls" order and then you require special script to work out the highest.
This User Gave Thanks to methyl For This Post:
# 3  
Old 07-30-2011
GNU cp has a -b|--backup option (see info coreutils - backup options). I believe it works exactly as you need.
# 4  
Old 07-31-2011
maybe someything like this could help if you know the number of files you want to copy for this example I am copying the file file 5 times to a folder named xfs

Code:
for i in {1..5}
 do 
  cp file xfs/file$i
 done

where xfs/ is the folder where you want to copy the file
# 5  
Old 07-31-2011
hey 10x 4 the suggestion... but no of times it is to be copied is not known in advance..
# 6  
Old 08-14-2011
how to assign multiple ip add in single ethernet card using unix cmds?
# 7  
Old 08-14-2011
Prathesh,I think you should open a new thread on your question. I don't see how your question is related to what the OP's question was, so if it is a new question, please open a new thread under the appropriate forum so that it gets the right attention, thanks.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Replace string and create new file multiple times

First of all, apologies if this has already been answered elsewhere. I haven't quite been able to find what I'm looking for yet, so hopefully this won't come across as repetition. I have a file consisting of ~100 nearly identical lines, each of which contains multiple instances of the string I... (11 Replies)
Discussion started by: pseudo.seppuku
11 Replies

2. Shell Programming and Scripting

Trying to do multiple dir's and multiple file names etc.

What am I missing? find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing... (3 Replies)
Discussion started by: xgringo
3 Replies

3. Shell Programming and Scripting

Inserting text in file names while copying them.

I'm trying to find a Bourne shell script that will copy files from one directory using a wild card for the file name (*) and add some more characters in the middle of the file name as it is copied. As an example: /u01/tmp-file1.xml => /u02/tmp-file1-20130620.xml /u01/tmp-file2.xml => ... (6 Replies)
Discussion started by: Tony Keller
6 Replies

4. UNIX for Dummies Questions & Answers

How to check if the same file exists multiple times?

Hi Team , Is there a way I can check to see if the same file say , test.dat exists multiple times in the directory path ? Please help. Thanks Megha (5 Replies)
Discussion started by: megha2525
5 Replies

5. Shell Programming and Scripting

Copying List of Files Under Different File Names ?!

Hi to all here , Excuse me for the lamer question but I need UNIX command for copying List of Files Under Different File Names ! for example I have this list: new_001.jpg new_002.jpg new_003.jpg ..... I want to copy all files that start with "new_" to the same directory but under... (7 Replies)
Discussion started by: boboweb_
7 Replies

6. Shell Programming and Scripting

Append some text to a file multiple times

Hi, I have a text file like Version=abc Tab=1 URL GOTO=www.abc.com/board=1 some text... I want to run a loop x no of times and append to the text file above text but URL GOTO should be www.abc.com/board=2 then 3,4...etc till x. Kindly help (2 Replies)
Discussion started by: krabu
2 Replies

7. Shell Programming and Scripting

call a passwd file to a script multiple times

Hello everybody, I have a requirement in my script.. When i'am executing a script, it'll ask a passwd of some service account.. I need to pass it to the script through a zipped file when it asks for it. The script can be executed by more people many number times. So for securty purpose, it... (1 Reply)
Discussion started by: raghu.iv85
1 Replies

8. UNIX for Dummies Questions & Answers

Copying files multiple times increasing sequentially

I am looking for the easiest way to copy a set of files 1000 times and increment sequentially. I want to copy these 2 files: Scenario.1.1.ud Scenario.1.2.ud So that it creates the following: Scenario.2.1.ud Scenario.2.2.ud Scenario.3.1.ud Scenario.3.2.ud .. .. Scenario.1000.1.ud... (2 Replies)
Discussion started by: JPOrlando
2 Replies

9. UNIX for Dummies Questions & Answers

Copying multiple folders to local machine (don't know folder names)

Hi. I'm trying to copy multiple folders from the remote machine to the local machine. I wrote a batch file to run an ftp window. The problem I am having is that the only command to copy files is mget *, and this copies only files, not folders. For example, ftp ts555 cd ts555/test ' test... (5 Replies)
Discussion started by: leenyburger
5 Replies

10. UNIX for Dummies Questions & Answers

Copying file names returned from a grep command into another directory

When I do the following : grep -l "string" *, I get a list of file names returned. Is there a way to copy the files returned from the list into another directory ?. Thanks. (4 Replies)
Discussion started by: Kartheg
4 Replies
Login or Register to Ask a Question