Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to replicate a single directory (with sub-directories) to a bunch of new directories based on a list. For example I can:

mkdir Fred Barney Thelma Louise Foo Bar

How would I copy a premade directory (with some empty sub-directories) to the same set of names? For example:

cp -r master_folder/ Fred Barney Thelma Louise Foo Bar

Any suggestions much appreciated!

share|improve this question
add comment

2 Answers

Use a loop to iterate over the directories you want it copied to and copy the contents of your master directory to each one:

dest=(Fred Barney Thelma Louise Foo Bar)
for d in "${dest[@]}"; do
    cp -r master "$d"
done
share|improve this answer
    
Thank you htor. I seem to get errors when I use the above. If I remove the wildcard after master/ it works but only makes the first folder 'Fred' Tried to vote it up, but need a rep of 15... –  user30191 Jan 12 '13 at 20:40
    
@user30191 Fixed that problem. –  Herman Torjussen Jan 12 '13 at 21:09
    
+1 for showing the syntax for bash arrays :) –  rahmu Jan 13 '13 at 2:14
add comment

If your directory names don't contain any special characters (whitespace or \"'):

echo Fred Barney Thelma Louise Foo Bar | xargs -n1 cp -r master_folder

This can also by written:

xargs -n1 cp -r master_folder  < <(echo Fred Barney Thelma Louise Foo Bar)

or more explicitely, through a bash loop (this works for arbitrary file names):

for user in Fred Barney Thelma Louise Foo Bar ;do
    cp -r master_folder "$user"
  done
share|improve this answer
    
Thank you F.Hauri! That works well. Great site here. Wish I knew a little something something to help in return... Tried to vote it up, but I need a rep of 15... –  user30191 Jan 12 '13 at 20:42
    
U could accept this response as you're the asker –  F. Hauri Jan 12 '13 at 20:55
add comment

Your Answer

 
discard

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.