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?
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
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.
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 )
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
.