Hi,
I want to copy a full and complex directory structure into another directory but without copying any file. The ONLY thing I want to copy is directory structure, one the same as I created some time.
I was reviewing the man of cp command but I didn’t see anything there.
Any other suggestion, please ?
Thanks in advance fo any feedback,
Regards,
Agustin
Miuku
January 25, 2015, 1:17pm
#2
cd to the directory you want to copy the directory structure from and;
find ./ -type d -exec mkdir -- /destination/directory/{} \;
So for example you want to copy the structure of /root/meow to /tmp/woof/
cd /root/meow
find ./ -type d -exec mkdir -- /tmp/woof/{} \;
Oughta do the job. Just popped into my mind
hcvv
January 25, 2015, 1:34pm
#3
Miuku:
cd to the directory you want to copy the directory structure from and;
find ./ -type d -exec mkdir -- /destination/directory/{} \;
So for example you want to copy the structure of /root/meow to /tmp/woof/
cd /root/meow
find ./ -type d -exec mkdir -- /tmp/woof/{} \;
Oughta do the job. Just popped into my mind
Good idea. Are we sure that find gives the directories in hierarchical sequence? If not use mkdir -p instead of mkdir.
Miuku
January 25, 2015, 1:35pm
#4
Good point hcvv, I assumed (the bad start to everything?) that find would traverse the directories in a sequential order.
hcvv
January 25, 2015, 1:56pm
#5
I did a quick test. As far as I can see it is hierarchical, thus the -p option is not needed. But it does not hurt of course.
Hi,
source=/somewhere
destination=/outhere
find "$source" -type d -print | pax -rwdv "$destination"
or if you don’t like pax you can use cpio
find "$source" -type d -print | cpio -pdumv "$destination"
Hi,
you might need to cd to the source directory to avoid copying the parent directory (unless that is intended) which is done in my previous post.
source=/somewhere
destination=/outhere
I am using a subshell ( and** )** so you don’t have to worry about going to the directory you are in after the command is done
( cd "$source" && find . -type d -print | pax -rwdv "$destination" )
or
( cd "$source" && find . -type d -print | cpio -pdumv "$destination" )