Server Fault is a question and answer site for system and network administrators. 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 folder named test which has files and subdirectories in it. I want to copy the content of this test folder to another folder named live and here is what I did:

cp -pr /path/to/test/ /path/to/live/

But what I get is a folder test inside the live folder, but I don't want that. Then I tried this:

cp -pr /path/to/test/*.* /path/to/live/

But all I got was just files.

So, please tell me where am I doing it wrong.

share|improve this question
up vote 3 down vote accepted

You're copying recursively, so no need for any wildcards.

cp -pr /path/to/test/. /path/to/live/
share|improve this answer
wouldn't this make a dir test in dir live? – Nikola Jul 13 '11 at 8:50
Sorry, add trailing slash and it wont. – 3molo Jul 13 '11 at 15:14
this is exactly what I did and I got a folder test inside the folder live – Nikola Jul 13 '11 at 15:58
You need to add a trialing period to the first path name. Fixed that for you. Or, use rsync: rsync -a /path/to/test/ /path/to/live/ – MikeyB Jul 13 '11 at 18:19

*.* implies files since you've specified an extension. You're using recursion (-r) so just use /* in place of /*.* and you should get folders.

share|improve this answer
ah, I figured it out when posting, but thanx for your reply, will mark it as correct. – Nikola Jul 13 '11 at 8:46
@Nikola No probs, thanks! – Gargravarr Jul 13 '11 at 9:00
I wish to note that the cp command itself, never 'sees' the asterisks, but they are expanded by the shell prior to cp being run. This means if there are 20 items in /path/to/test/ then cp is run with its -pr switch, plus 21 filenames/paths. The last one listed is treated as the destination. This means that using *.* will also pickup folder names that contain an internal dot. If you want to also get hidden files and folders set the bash dotglob option shopt -s dotglob. You can test the effect of globbing using the echo command, e.g. echo * and echo *.* – JeffG Jul 13 '11 at 17:27
INCORRECT - this answer will miss any .dotfiles present in the directory. – MikeyB Jul 13 '11 at 18:21
@MikeyB: thank you for the update, I have corrected my correct answer – Nikola Jul 15 '11 at 6:11

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.