Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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 want to copy a file "" in directories which have all a subdirectory 2_bas (ex. prod1/2_bas, prod2/2_bas, etc...)

I tried:

cp test */2_bas/

but I get the error message:

cp: omitting directory `prod1/2_bas'
cp: omitting directory `prod2/2_bas' 

A solution would be:

for dir in *; do [ -d "$dir" ] && cp "$dir"/2_bas ; done

But why does the first strategy not work?

share|improve this question
up vote 4 down vote accepted

It's how the cp command is designed to work; it accepts multiple sources but only one destination. So your expansion looks like:

cp test prod1/2_bas prod2/2_bas prod3/2_bas .... prodN/2_bas

and what you're telling cp is to essentially copy everything into prodN/2bas (the last directory in the expansion). This is certainly not what you want. The error message you see is because you're telling cp to copy directories, and by default it refuses to do so (unless you specify, for instance, -r for recursive copying. Don't do it, though; it will still not do what you want).

Have a look at cp man page, it states what the command does:

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

Another solution:

find ./ -type -d exec cp test {} \;
share|improve this answer

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.