Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I do this on the command line?

e.g. copy /dir/another/file to /tmp/ so I have /tmp/dir/another/file

share|improve this question
4  
Please edit and provide an example of what you are trying to achieve –  Paul Jul 25 '12 at 14:10
    
My guess is that he wants to copy foo1/bar/cdr/myfile to /dstdir and have it create /dstdir/foo1/bar/cdr/myfile –  Nifle Jul 25 '12 at 14:26

3 Answers 3

up vote 11 down vote accepted
cp --parents /dir/another/file /tmp

will do exactly what you want.

share|improve this answer

rsync can be a good help for this :

rsync -Ravz my/first/dir/file.txt another_dir

will gave as result

another_dir/my/first/dir/file.txt
share|improve this answer

You can use tar to preserve paths while copying files:

tar cf - /dir/another/file | (cd /tmp && tar xf -)
share|improve this answer

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.