How can I replicate a dir hierarchy preserving permissions and ownership?

Hi,

If I have:
base/d0/d1/d2

and want to replicate it:
base1/d0/d1/d2

How can I do this preserving permissions and ownership without copying files.
 
That reads as "how do I copy files without copying files?" It's like a Zen koan.

Are you asking how to copy a directory without copying individual files?
See the -p and -R options for cp(1), but I prefer net/rsync with -a and maybe -H, depending:
# rsync -a base/ base1/
 
wblock said:
That reads as "how do I copy files without copying files?" It's like a Zen koan.

Are you asking how to copy a directory without copying individual files?

I want to replicate the hierarchy only without the files inside. Something similar to:
[CMD=""]install -d base1/d0/d1/d2[/CMD]
but preserving permissions and ownership from base0.
 
meh, mtree is not available in GNU systems apparently.
Is there a way that works in more platforms?
 
Yes, you can script it using find -type d -ls to get the directory tree, permissions, and ownership. Then pass that into xargs or whatever to re-create the tree and set ownsership/permissions.
 
Back
Top