Take the 2-minute tour ×

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
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
add comment

3 Answers

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

will do exactly what you want.

share|improve this answer
add comment

You can use tar to preserve paths while copying files:

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

rsync can be a good help for this :

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

will gave as result

share|improve this answer
add comment

Your Answer


