0

I want a script to copy the same file from source folder to target folder by incrementing the filename (ex. file1, file2, file3, file4,....). This would be for some performance testing.

I've got this code so far, but how best can it be achieved?

#!/bin/sh
for i in 1 2
do cp /tmp/ABC*/folder1/ABC*$i
done
5
  • #!/bin/sh for i in 1 2 do cp /tmp/ABC* /mnt/share/reception/13_calling_cards_data/ABC*$i done
    – Learner
    Jan 13 at 14:12
  • Do you want the same source file copied to the same target or a different target each time?. It's not clear from your question whether you want (A→A) repeated n times, or (A→Aⁿ) for increasing values of n.
    – roaima
    Jan 13 at 14:17
  • Richard, is that comment of yours your own suggestion as a starting point, or a solution that you're now using?
    – roaima
    Jan 13 at 14:26
  • hi @roaima I want to copy the same file from source folder to target folder but just by incrementing the filename (ex. file1, file2, file3, file4 ....) continuously.
    – Learner
    Jan 13 at 14:37
  • you can't use a wild card (as a wild card) in the target name. Other than that, the approach works. Put your file name in a variable, put your target directory in a variable, and you'll be all set :) Jan 13 at 14:45

1 Answer 1

1

You want a forever-repeating loop

#!/bin/sh
n=1
while true
do
    cp /tmp/ABCfile "/mnt/share/reception/13_calling_cards_data/ABCfile.$n"
    n=$(( n+1 ))
done
1
  • Thanks @roaima :)
    – Learner
    Jan 13 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.