Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 1 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
share|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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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