I have Eclipse projects and ".project" file in them, the directory structure looks like 'myProject/.project'. I want to copy these '.project' files to another directory, but I want the enclosing directory name to be preserved.

Let's say I have 'a/myProject/.project', I want to copy 'myProject/.project' to 'b', so it be 'b/myProject/.project', but 'b/myProject' doesn't exist. When I try in a:

 cp -r ./myProject/.project ../b

it copies only '.project' file itself, without 'myProject' directory. Please advise.

link|improve this question
feedback

3 Answers

up vote 5 down vote accepted

The switch you need is --parents eg:

jim@prometheus:~$ cp --parents test/1/.moo test2/
jim@prometheus:~$ ls -la test2/
total 42
drwxr-xr-x 3 jim jim 72 2010-09-14 09:32 .
drwxr-xr-x 356 jim jim 43136 2010-09-14 09:32 ..
drwxr-xr-x 3 jim jim 72 2010-09-14 09:32 test
jim@prometheus:~$ ls -la test2/test/1/.moo
-rw-r--r-- 1 jim jim 0 2010-09-14 09:32 test2/test/1/.moo

link|improve this answer
feedback

cp -P a/myProject/.project b

see "man cp" for more information.

link|improve this answer
This doesn't seem to help. It only copies '.project' itself into b, but it doesn't copy 'myProject'. – gasan Sep 14 '10 at 8:11
feedback

Use tar with something like:

mkdir b; tar cpf - myProject/ | tar xpf - -C b/

(not tested, give it a dry run first or try in a mockup scenario)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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