Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 want execute this cp debian.master/abi/2.6.38*/amd64/generic debian.master/abi/2.6.38*/amd64/core2 but bash gives error in second *:

cp: cannot create regular file `debian.master/abi/2.6.38*/amd64/core2': No such file or directory

How can I copy one file in same dir but when other name without to change of dir nor to write the entire folder name?

share|improve this question
up vote 3 down vote accepted

The error is because the shell try to expand * glob character before executing the command, and the destination do not exist yet. One possibility to overcome this would be

cp debian.master/abi/2.6.38*/amd64/generic "$(eval echo debian.master/abi/2.6.38*/amd64)"/core2

More simply you can do:

( cd debian.master/abi/2.6.38*/amd64/; cp generic core2 )

Or also

cp "$dir"/generic "$dir"/core2
share|improve this answer
Thanks, the second method is more simple but it would be: ( cd debian.master/abi/2.6.38*/amd64/; cp generic core2; ) – Juan Simón May 6 '11 at 14:50
Ah, ok. I would not spawn a subshell, but in such a case the cd remain in effect. I edit the answer – enzotib May 6 '11 at 14:52
The first one, using eval, is dangerous. eval should be avoided at all cost. The last one won't work since glob expansion does not occur in variable assignments or inside quotes. I'd do for f in debian.master/abi/2.6.38*/amd64/generic; do cp "$f" "${f%/generic}/core2"; done – geirha May 6 '11 at 21:06
@gheira: ok for eval, but the last one works imho, as long as the * is not quoted and the expansion gives only one string, as I think the user suppose. – enzotib May 7 '11 at 5:19

Assuming debian.master/abi/2.6.38* expands to multiple directories:

for dir in debian.master/abi/2.6.38*/amd64; do cp $dir/generic $dir/core2; done
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.