1834882 Members
2338 Online
110071 Solutions
New Discussion

Copy directory structure

 
SOLVED
Go to solution
Rafael Casero
Regular Advisor

Copy directory structure

I'm trying to copy only the directory structure and not the files within.

Can't seem to find the proper "cp" option to perform this task.

Thanks,
4 REPLIES 4
Pete Randall
Outstanding Contributor
Solution

Re: Copy directory structure

How about something like this:

for i in `find /start_dir -type d`
do
mkdir $i
done


Pete

Pete
A. Clay Stephenson
Acclaimed Contributor

Re: Copy directory structure

That's because you are using the wrong tool. The following will copy the directory structure (only directories) and leave the modes and ownership intact.

1) cd to desired starting point in the source tree
2) find . -type d -print | cpio -ocv > /var/tmp/cpio.dat

3) cd to directory above the desired destination tree.
4) mkdir mynewdir # or whatever
chmod 750 mynewdir # or whatever
chown me:mygroup mynewdir # or whatever
5) cd mynewdir # or whatever
6) cpio -icvdum < /var/tmp/cpio.dat

If it ain't broke, I can fix that.
Wessam Aly
Frequent Advisor

Re: Copy directory structure

you can also simply do this

find /start_dir -type d -exec mkdir -p /top_destination_dir/{} \;

that'll create your directory structure in one fell swoop
The manual said the program requires Windows 95 or better, so I installed Linux !
Rafael Casero
Regular Advisor

Re: Copy directory structure

A_Clay was the answer to my question.

I was not able to make the one swoop command work.

Thanks, to all...