I have directory A with subdirectory B and am trying to copy everything from B to A. Within A, I run

cp -ar B/ ~/A, 

and get the message that

"cp: âB/â and â/u/username/A/Bâ are the same file"

However, I'm not sure why it thinks the destination would involve B.


In general, this attempts to copy B, not its contents, into A. Since B is already a subdirectory of A, cp is rightly saying that the source and destination are the same file.

If you instead want to copy the contents of B into A, you want:

cp -ar /path/to/A/B/* /path/to/A/

If A is your current working directory, then this works instead:

cp -ar B/* .
|improve this answer|||||
  • His current directory is already A. So, cp -ar B/* . will do. – Thushi Feb 2 '17 at 4:08

The command cp -ar B/ ~/A won't only copy the contents of B but the whole B itself which is already present in A. So, try running cp -ar B/* . within the directory A.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.