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
?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityI 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
?
Try this
for f in {1..5}; do cp my.jpg my$f.jpg; done
(don't have bash here to try it myself)
seq
isn't necessary in Bash. You can use for f in {1..5}
or for ((f=1; f<=5; f++))
Jan 18, 2012 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.
Try tee
:
tee <my.jpg >/dev/null my-{1..5}.jpg
Or parallel
:
parallel cp my.jpg ::: my-{1..5}.jpg
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
<"$pre$suf" tee "$pre"{1..5}"$suf"
works just fine.
Jan 18, 2012 at 16:08