cp -av Doubling directory

0

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/scala

The 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

Jake

Posted 2018-02-15T05:01:37.023

Reputation: 107

Look at the source directories - I suspect you will find that all the code is in .../test/scala/scala – davidgo – 2018-02-15T09:49:54.030

Answers

1

Consider cp a b/c.

  1. If c doesn't exist (and b does), it will be interpreted as a name for the copy of a, so you will end with b/c.

  2. On the other hand if c does exist and it's a directory, it will be interpreted as a path where to place a under the unchanged name a, so you will end with b/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.

Kamil Maciorowski

Posted 2018-02-15T05:01:37.023

Reputation: 38 429

Kamil, your answer was helpful...but fyi, the issue was with a hidden file (see my answer below) – Jake – 2018-02-17T03:17:53.553

0

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

Jake

Posted 2018-02-15T05:01:37.023

Reputation: 107