The Computer Oracle

How can I copy a single file and maintain directory structure?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Ocean Floor

--

Chapters
00:00 How Can I Copy A Single File And Maintain Directory Structure?
00:17 Answer 1 Score 5
00:30 Accepted Answer Score 26
00:40 Answer 3 Score 3
00:49 Thank you

--

Full question
https://superuser.com/questions/453418/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #filemanagement

#avk47



ACCEPTED ANSWER

Score 26


cp --parents /dir/another/file /tmp

will do exactly what you want.




ANSWER 2

Score 5


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



ANSWER 3

Score 3


You can use tar to preserve paths while copying files:

tar cf - /dir/another/file | (cd /tmp && tar xf -)