a script to clone a dir tree, & overwrite the dir struct elsewhere?

hi all,

i'm looking for a bash or tcsh script that will clone an empty dir tree 'over' another tree ...

specifically, i'd like to:

(1) specify a src directory
(2) list the directory tree/hiearchy beneath that src dir, w/o files -- just the dirs
(3) clone that same, empty dir hierarchy to a NEW OR EXISTING specified dir target, creating dirs/subdirs as necessary
(4) all ORIG dir ownership/perms should be preserved/corrected in the target tree

any obvious/existing solutions? i'd have thought this exists already somewhere ...

thx!

richard

Check out this post - Copying a Directory Structure to a new structure

Hi Richard,

The tar command can be used to reproduce a directory tree with all the ownership and permissions preserved (though arbitary preserved ownership is only possible if you untar as root).

By combining with the find and xargs command it is possible to tar a directory tree with none of the files in it saved.

To make the compacted tree, use this command from the directory root you want to copy the tree from...

find . -type d -print0 | xargs -0 tar -f tree.tgz --no-recursion -zpc

This creates a file called tree.tgz. Copy this file to the directory you want to copy the tree to then just type...

tar zxf tree.tgz

I recommend testing this in an empty directory before letting it loose on a source tree just to make sure it creates the tree in the way you expect e.g. at the right directory level.