Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I can move 5 files to somewhere using:

$ mv my-{1..5}.jpg /path/to/dir/

How can I make copy of one file by 5 times easily

# doesn't work
$ cp my.jpg my-{1..5}.jpg

Is it possible not to use a for loop?

share|improve this question
up vote 4 down vote accepted

Try this

for f in {1..5}; do cp my.jpg my$f.jpg; done

(don't have bash here to try it myself)

share|improve this answer
replace for f in $f with for f in $(seq 5). – Dan D. Jan 18 '12 at 1:36
Is it possible not to use a for loop? – kev Jan 18 '12 at 1:38
@kev - I've always seen it done this way; also, more readabe. – Rook Jan 18 '12 at 1:48
@kev, what is wrong with a for loop? This is what for loops are for... – soandos Jan 18 '12 at 2:10
@DanD.: seq isn't necessary in Bash. You can use for f in {1..5} or for ((f=1; f<=5; f++)) – Dennis Williamson Jan 18 '12 at 15:57

Here is a way to do it without a for loop and without the risks of using eval:

printf '%s\n' {1..5} | xargs -I {} cp my.jpg my-{}.jpg

It's still effectively a loop.

share|improve this answer

You can do it without a loop.. using tee and {} brace expansion.

EDIT: (ammended as per Dennis Williamson's comment:

For a file named "my-.jpg"

pre="my-"; suf=".jpg"
<"$pre$suf" tee "$pre"{1..5}"$suf" >/dev/null
share|improve this answer
It's not necessary to use eval. <"$pre$suf" tee "$pre"{1..5}"$suf" works just fine. – Dennis Williamson Jan 18 '12 at 16:08
@Dennis: So it does.. thanks :) – Peter.O Jan 18 '12 at 16:26

Try tee:

tee <my.jpg >/dev/null my-{1..5}.jpg

Or parallel:

parallel cp my.jpg ::: my-{1..5}.jpg
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.