Copy a Directory Along With Its Relative Path

Today, a friend of mine wanted to do this:

Copy a directory from path A to path B, preserving its relative path.

For example, if the directory is found at:

./old/path/of/dir

and we want to copy it to

./new/place/

We want the result look like this:

./new/place/old/path/to/dir

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

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

And we’re done.


If you enjoyed this post, make sure you subscribe to my RSS feed!

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Related posts:

  1. Google Reader Useful “Send To” Services
  2. Make Shell Scripts Executable By Default

Tags: ,

Sunday, March 22nd, 2009 Bash

Leave a Reply

my email
my photo
Hi,
My name is Amir Watad. I have a BSc. in biomedical engineering from The Biomedical Engineering school , Technion , Israel, and a BSc. in electrical engineering from The Electrical Engineering school , Technion , Israel.
I'm a Verification Engineer in Mellanox Technologies Ltd.
I love Linux, the Command Line and the OpenSource Community.
I used to write Poems (Arabic) when I was able to find time for this.
March 2009
S M T W T F S
« Feb   May »
1234567
891011121314
15161718192021
22232425262728
293031  
SEO Powered by Platinum SEO from Techblissonline

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.