cp says "same file" for two different directories
19,956
Solution 1
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/* .
Solution 2
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
.
Related videos on Youtube
Author by
user213757
Updated on September 18, 2022Comments
-
user213757 almost 2 years
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.
-
Julie Pelletier over 7 yearsWhere are these
â
coming from?
-
-
Thushi over 7 yearsHis current directory is already
A
. So,cp -ar B/* .
will do.