cp -av /home/jake/transit/scalaProjects/scalaML/src/main/scala /home/jake/project/__workspace/scalaProjects/scalaML/src/main/scala
cp -av /home/jake/transit/scalaProjects/scalaML/src/test/scala /home/jake/project/__workspace/scalaProjects/scalaML/src/test/scalaThe first line copies to /src/main/scala
BUT
the second copies to /src/test/scala/scala
I am on Ubuntu server 16.
I am sure I am missing something, but I am confused. ANy help would be appreciated
12 Answers
Consider cp a b/c.
If
cdoesn't exist (andbdoes), it will be interpreted as a name for the copy ofa, so you will end withb/c.On the other hand if
cdoes exist and it's a directory, it will be interpreted as a path where to placeaunder the unchanged namea, so you will end withb/c/a.
I guess in the beginning /home/jake/project/__workspace/scalaProjects/scalaML/src/main/scala doesn't exist, there's only /home/jake/project/__workspace/scalaProjects/scalaML/src/main/.
Your first command creates scala acting as (1). It may be somewhat confusing because you have scala in place of a and c, so it's not obvious that some trivial renaming takes place (from scala to scala). Then the second command acts as (2).
This command will work as your first one, regardless if the target scala exists, if only /home/jake/project/__workspace/scalaProjects/scalaML/src/main/ exists:
cp -av /home/jake/transit/scalaProjects/scalaML/src/main/scala /home/jake/project/__workspace/scalaProjects/scalaML/src/main/But if /home/jake/project/__workspace/scalaProjects/scalaML/src/main/ doesn't exist and /home/jake/project/__workspace/scalaProjects/scalaML/src/ does, your scala will be placed there under the name main. This is behavior (1) again.
To get rid of this ambiguity use -t:
cp -av /home/jake/transit/scalaProjects/scalaML/src/main/scala -t /home/jake/project/__workspace/scalaProjects/scalaML/src/main/This makes cp interpret main as a directory where you want to place scala. No renaming will take place. If /home/jake/project/__workspace/scalaProjects/scalaML/src/main/ doesn't exist, cp will throw an error.
I have found the problem and solution. A hidden file remained in the directory even though I had attempted a full delete fo the directory previously (rm -rf).
This file .fuse_hidden was created by the file system because an SFTP server session still held a link to the file. (I had previously opened a file in that directory via mobaxterm).
Closing down the session on my mobaxterm terminal that had opened the file, led to the removal of the hidden file and then all else worked fine. Note that closing down the file I had opened remotely was insufficient to resolve the problem.
see here for a better explanation