Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Say, if I wanted to make N copies of a.txt, and wanted them to be numbered a1.txt, a2.txt, a3.txt, etc...

How would I do such a thing succinctly?

share|improve this question

3 Answers 3

up vote 7 down vote accepted

cp itself can only make one copy (of a single file) at a time, but it's not too difficult with a quick loop:

for i in {1..10}; do cp a.txt a$i.txt; done
share|improve this answer

Assuming you have your N value in a bash variable:

for i in `seq 1 $N`; do cp a.txt a$i.txt; done

or

for ((i=1;i<=$N;i++)); do cp a.txt a$i.txt; done

or with the loop shown in Kevin's answer.

share|improve this answer

If you want something more funky, you can for example do: for t in $(seq --format="funky-%03.0f-numbered.txt" 25 3 40); do cp orig $t; done.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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