Copy a Directory Along With Its Relative Path

How to copy a directory from path A to path B, preserving its relative path?

For example, if the directory is found at:


and we want to copy it to


We want the result look like this:


The trick is to use the –parents flag of the “cp” command. So this command will do the job:

cp -r --parents old/path/to/dir new/place/.

And we’re done.

Leave a Reply