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



## Nezmer (Jul 24, 2010)

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.


----------



## wblock@ (Jul 24, 2010)

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/`


----------



## Nezmer (Jul 24, 2010)

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.


----------



## fairy (Jul 24, 2010)

use mtree(8) then
`# mtree -cdp /path/to/source | mtree -Up /path/to/destination`


----------



## Nezmer (Jul 24, 2010)

fairy said:
			
		

> use mtree(8) then
> `# mtree -cdp /path/to/source | mtree -Up /path/to/destination`



Awesome.
Why do you have 0xffffffff thanks?


----------



## Nezmer (Jul 24, 2010)

meh, mtree is not available in GNU systems apparently.
Is there a way that works in more platforms?


----------



## fronclynne (Jul 24, 2010)

find(1)?


----------



## Nezmer (Jul 25, 2010)

fronclynne said:
			
		

> find(1)?


Really!


----------



## phoenix (Jul 26, 2010)

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.


----------

