Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

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
up vote 19 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .