2

I'd like to know if it is possible to duplicate a single file to multiple files with a different list of arguments. I have a generic image and I need to make multiple copies of it adding a different country extension to each copy.

I tried optimistically:

cp -r centre-stage-synopsis.jpg centre-stage-synopsis-{en_US,fr_FR,de_DE,da_DK,ru_RU,pt_BR,ro_RO,hu_HU,el_GR,it_IT}.jpg

But it doesn't work. Is there a way to do this in one go?

Cheers

terdon
  • 52,568
  • 14
  • 124
  • 170
  • 1
    On a side-note: Why do you want to keep so many copies of a single image? Wouldn't symlinks be better? – Dennis Jul 26 '12 at 17:47
  • It's a bit of a contrived example. I need various copy of the same image to be used wit site locales. Normally images would be different, but on this occasion they are the same. Just the system needs them. – Yannick Schall Jul 26 '12 at 18:22

2 Answers2

7

Not sure if zsh allows this, so please feel free to smack me if the syntax is significantly off that you can't figure out how to translate this.

I am going to post a code fragment that should do what you want from either the sh, dash, or bash shells (basically anything from the Bourne family).

for i in en_US fr_FR de_DE da_DK ru_RU pt_BR ro_RO hu_HU el_GR it_IT; do cp -r centre-stage-synopsis.jpg centre-stage-synopsis-$i.jpg; done

Good luck, and as I said, smack me if zsh doesn't like it. :)

allquixotic
  • 34,215
  • 7
  • 113
  • 145
  • 1
    This works just fine in `zsh`. The `-r` switch is obsolete though. – Dennis Jul 26 '12 at 17:50
  • I wasn't sure why the OP was insisting on the `-r` flag myself, but I figured I'd just blindly copy the structure/contents of his example into a proper `for` loop so that he could see what I did without me throwing him a curveball. He should be able to compare his ill-fated incantation with mine and see exactly what I did with his original code. – allquixotic Jul 26 '12 at 17:53
  • I'm quite certain it was parts of the "optimistic attempt" to expand the insides of the brackets. – Dennis Jul 26 '12 at 17:56
4

If you have multios and brace_expand enabled (they should be on by default) you can do it with cat:

cat centre-stage-synopsis.jpg \
  >centre-stage-{en_US,fr_FR,de_DE,da_DK,ru_RU,pt_BR,ro_RO,hu_HU,el_GR,it_IT}.jpg
Thor
  • 6,419
  • 1
  • 36
  • 42