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

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:

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.

GNU cp has a -b|--backup option (see info coreutils - backup options). I believe it works exactly as you need.

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

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

where xfs/ is the folder where you want to copy the file

hey 10x 4 the suggestion... but no of times it is to be copied is not known in advance..

how to assign multiple ip add in single ethernet card using unix cmds?

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.