How to copy retaining relative path


From a certain directory I wanted to copy a file a/b/c.txt to a destination. But I wanted the relative path a/b to be retained at the destination. A normal copy would just copy c.txt to the destination.


There is no way to do this using the cp command. One solution is to use rsync which supports maintaining the relative file path.

For example:

$ pwd
$ rsync -R a/b/c.txt /home/joe/destination

This copies c.txt to /home/joe/destination/a/b automatically creating a/b if they do not exist in the destination.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.