Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have to copy a file in a directory, to its backup directory, preserving the folder structure. Ex. The file aaa in MyFolder/Test/aaa to .MyFolder.bck/Test/aaa

I tried to use

cp --parents MyFolder/Test/aaa .MyFolder.bck;

But the result is .MyFolder.bck/MyFolder/Test/aaa and not .MyFolder.bck/Test/aaa that is the one I want.

Thank you in advance.

share|improve this question
    
Duplicate –  scai Apr 25 '13 at 8:10
add comment

2 Answers

I think you can only do this:

cd MyFolder
cp --parents Test/aaa ../.MyFolder.bck
share|improve this answer
add comment

Obviously you can do

( cd MyFolder ; cp --parents Test/aaa ../.MyFolder.bck )

and I assume that doesn't fit your needs.

You can use tar for that:

tar -cf - MyFolder/Test/aaa | tar -C .MyFolder.bck --strip-components 1 -xf -
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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