Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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

 
discard

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.