Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a file that I want to copy to another 60 directories.

The best way I can think of doing this is by making a bash script that has instructions to every folder like this:

cp script.sh /home/user/dl/*/111/23
cp script.sh /home/user/dl/*/111/23
cp script.sh /home/user/dl/*/111/23
and so on...

The * is a number starting at 1 and finishing at 60

There has to be a better way than this.

share|improve this question
for((i=1;i<61;i++)); do
  cp -p script.sh /home/user/dl/${i}/111/23

Or, more fun:

eval "cp script.sh /home/user/dl/"{1..60}"/111/23;"
share|improve this answer
i do not think the eval option works, since cp takes only one directory at a time as target – iruvar May 2 '14 at 23:33
@1_CR Giving a try (with echo, of course) is often better than just thinking... – Hauke Laging May 2 '14 at 23:34
yes, actually works, sorry had used single quotes instead of double – iruvar May 2 '14 at 23:38
@1_CR Doesn't make a difference, does it? There's nothing to expand in the quoted string. The mistake must have been something different. – Hauke Laging May 2 '14 at 23:39
I had used something like this eval "cp script.sh "'dl/{1..10}'"/23/;". Got lazy and modified a previous example i was trying out instead of copying yours verbatim – iruvar May 3 '14 at 0:02

with bash and xargs

printf "%s\n" /home/user/dl/{1..60}/111/23/ | xargs -n 1 cp script.sh 
share|improve this answer
What's more, you could use xargs' -P option to execute in parallel, which could give a good speed-up depending on how the target directories are distributed on the underlying filesystem(s). – pimlottc May 3 '14 at 16:14

Your Answer


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.