General
cancel
Showing results for 
Search instead for 
Did you mean: 

How to copy directory structure only "with original ownership"

SOLVED
Go to solution
Unix Geek
Occasional Visitor

How to copy directory structure only "with original ownership"

I need to copy a directory structure in such a way that it contains all the directories/sub directories from a path AND it must retain the original owner/group permissions.

I should be able to generate the directory structure with following script

#!/bin/ksh
find -type d > /tmp/list_of_directories
for i in `cat /tmp/list_of_directories`
do
mkdir -p /DESTINATION/PATH/$i
done

The above script should be able to generate the directory structure with root/others owner and group but I want that it should get the original owner/group and the permissions from the source. Any ideas?
4 REPLIES
Dennis Handly
Acclaimed Contributor

Re: How to copy directory structure only "with original ownership"

You probably want to use find with cpio -p to copy just the directories. There is an example on find(1).
James R. Ferguson
Acclaimed Contributor
Solution

Re: How to copy directory structure only "with original ownership"

Hi:

# # cd srcdir && find . -depth -print | cpio -pudlmv dstdir

Regards!

...JRF...
Steven Schweda
Honored Contributor

Re: How to copy directory structure only "with original ownership"

A forum search for keywords like "tar
pipeline" should find some examples showing
how to use "tar" to do it. "man tar".

Visit a book store or library, and get a
basic book on UNIX?
Unix Geek
Occasional Visitor

Re: How to copy directory structure only "with original ownership"

Thanks to everyone who replied. I got my solution as below:

/usr/bin/find $SOURCE_DIR -type d -depth -print | cpio -pdulmv $DESTINATION_DIR

James: Your suggestion was very near to my solution (except -type d option in find command). Thanks again!