up vote 0 down vote favorite
2
share [g+] share [fb]

I want to replicate a complex directory structure from one Linux server to another remote server start at a certain sub-directory.

I don't want the contents of the files, I just want to preserve the structure, owner and permissions as the server to be cloned contains a large volume of data that must not be copied to the new machine.

I'm guessing that this could be done somehow by tar-ing up the folder structure and un-taring it on the remote machine. Or by using rsync to copy without sending the data. Or possibly by using find to create a shell script.

If anyone has the one-liner at hand that accomplishes this, I would appreciate it.

link|improve this question

67% accept rate
feedback

2 Answers

up vote 0 down vote accepted

You can combine find and cpio to make a list of subdirectories from the current working directory thus:

find . -type d -print | cpio -oO dirs.cpio

To rebuild that directory hierarchy on the remote machine, copy over the dirs.cpio file to the desired location and run:

cpio -iI dirs.cpio
link|improve this answer
Both answers were great but I'm giving the best answer to this for teaching me about cpio. – Stuart Woodward Dec 14 '09 at 1:20
feedback

one solution might be

find . -type d > dirs

to find the directories, then use that file with the -T option of tar:

tar cpzT dirs -f dest_file.tar.gz

which should create a compressed archive (z) preserving permissions (p) by archiving only the files listed (T dirs). Transfer file, uncompress with

tar xpzf dest_file.tar.gz

and you should be done.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.