How can I duplicate a file x times in a different directory with terminal?
Just prepend the directory name before the filename(s):
i=0; while ((i++ < 100)); do cp index /destination/directory/"index$i"; done
Replace /destination/directory
with the actual directory name.
This assumes the file you want to copy is in the current working directory.
Replace /path/to/destination
with the path to the real directory as required.index
should be replaced with the real filename if necessary:
for i in {1..100}; do echo cp -v -- index /path/to/destination/"index-$i"; done
Remove echo
after testing, and repeat the command to actually copy the files
It would be better to make the numbers fixed-width for easier sorting, ie 001,002... 010 etc, so you could use printf
:
for i in {1..100}; do printf -v new "index-%03d" "$i"; echo cp -v -- "index" /path/to/destination/"$new"; done
or more readably
for i in {1..100}; do
printf -v new "index-%03d" "$i"
echo cp -v -- "index" /path/to/destination/"$new"
done