My folder structure is like this:


Sometimes I need to re-structure the other ennumerated folders with a new default set of files and folders. For that end, I'm trying to copy the ideal folder base structure to the others, using the following:

cp -r ej-1/* ej-{2..12}/*

My expectation was:

ej-1/* -> ej-2/*
ej-1/* -> ej-3/*
ej-1/* -> ej-12/*

Instead, it copies the content of each folder to the last one, making some overwritting nonsense:

ej-1/* -> ej-12/*
ej-2/* -> ej-12/*
ej-3/* -> ej-12/*

What am I doing wrong?

1 Answer 1


Have a look at the cp manual, with man cp. The relevant parts are as follows.

       Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

By specifying multiple arguments, this is the format you are using. This copies multiple SOURCEs to a single DIRECTORY, which is not what you want. Instead, if you want to copy a single SOURCE to multiple directories, you could use something like a for loop, e.g.

for i in {2..12}; do cp -r ej-1/* ej-$i; done

N.B. This is untested. I've also removed the * globs from the destination, as they were unnecessary (from my interpretation of your question), and results in a single DIRECTORY for the cp command.

  • This works! Luckily, I have some basic programming knowledge built in me, yet utterly new to shell scripting. I didn't know the for is even simpler to write on a single line!
    – Fabián
    Oct 5, 2018 at 8:16
  • As for man: I'm actually on Windows using Cmder which has also a bash that I can execute and work with linux commands, and still the man command is not included, which is unfortunate. I wish to have it, but there's no documentation about installing it for this scenario.
    – Fabián
    Oct 5, 2018 at 8:17
  • @Fabián Glad it works! I can't really help with Cmder, but you should really try and get man working. It's a very accessible reference for these kind of things. (Sometimes a bit too terse, but definitely a good starting point.) I'm not sure if it's on topic here, but if not, maybe Superuser or somewhere else?
    – Sparhawk
    Oct 5, 2018 at 9:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .