Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 folder on a Linux server with 35+ subdirectories, along the lines of:

I have a file that I want to copy into each of those subdirectories. What's a quick way to do that without running 35+ separate cp commands manually?

share|improve this question
up vote 4 down vote accepted
for i in *; do
    cp file "$i"
share|improve this answer
what if there is a file in the current dir that matches * – bryan Sep 28 '11 at 17:25
@bryan: See updated answer. (FWIW, ls -d would have listed files as well.) – grawity Sep 28 '11 at 17:26
copied from the wrong terminal, added in my slash – bryan Sep 28 '11 at 17:31
That worked great, thanks! – Matt V. Sep 28 '11 at 17:44

find . -type d | xargs -I{} cp ./myfile {}/

This is how I got the job done.

Here was the problem I wanted solved. I wanted to test all my new virtual hosts before installing the actual applications.

find . -type d
find . -type d | xargs -I{} cp ./ {}/ 
ls ./*




share|improve this answer
for dirname in $(ls -d *; do cp file $dirname; done
share|improve this answer
... no for in $(ls), please. Wildcard expansion already works for all commands. – grawity Sep 28 '11 at 17:19

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.