Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

I think you can only do this:

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

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

Your Answer


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.