Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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


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

Solutions using cp are somewhat inefficient, because you don't need to read the same file N times to make N copies. One can use tee instead:

cat a.txt | ( for i in `seq 1 $N`; do echo a"$i".txt; done | xargs tee )
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

You could also use gnu parallel e.g.:

printf %s\\n {1..5} | parallel -j1 cp a.txt a{}.txt
share|improve this answer

Your Answer


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.