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 want to copy some or all files from a directory test/A/ to directory test/B/, but without copying directory A itself.

I tried the command cp -R test/A/ test/B, but it copies the directory and the files as well and become test/B/A/

share|improve this question

When you specify test/A/, you tell Bash to copy the directory itself.

To copy only the contents of a directory, use the * glob:

cp -R test/A/* test/B

Here, * will match all files in A, except hidden ones prefixed with a dot, e.g. .htaccess. To include these as well with a *, call shopt -s dotglob before.

share|improve this answer

to get an identical copy locally or remote I would prefer rsync over cp. This gives you much finer control over what should be copied or even deleted either on source or destination if so desired. And by the way fixes issues with hidden files (aka .*). Basic usage is as simple as with cp though.

to copy a directory A and it's contents to B use:

rsync -va test/A test/B

to copy the contents of directory A (including hidden files) to B use:

rsync -va test/A/ test/B

if B does not exist it's created

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.