duplicate a single file to a list of files

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

Yannick Schall

Posted 2012-07-26T17:35:27.997

Reputation: 123

1On a side-note: Why do you want to keep so many copies of a single image? Wouldn't symlinks be better? – Dennis – 2012-07-26T17:47:56.603

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 – 2012-07-26T18:22:33.853

Answers

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

Posted 2012-07-26T17:35:27.997

Reputation: 32 256

1This works just fine in zsh. The -r switch is obsolete though. – Dennis – 2012-07-26T17:50:19.060

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 – 2012-07-26T17:53:05.033

I'm quite certain it was parts of the "optimistic attempt" to expand the insides of the brackets. – Dennis – 2012-07-26T17:56:27.377

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

Posted 2012-07-26T17:35:27.997

Reputation: 5 178

I love you people!!! – Yannick Schall – 2012-07-26T18:26:49.637