script to create same directory stucture
Hi,
I want to write a script which will create the same directory structure on the other server. one of the directory has many sub directories and few sub directories have some more sub directories in it. I want to have exact directory structure without any files. Best Regards, KJ. |
Just one command:
Code:
rsync -av --include '*/' --exclude '*' /path/to/dir user@host: |
This may help you in creating empty directories.
[user@machine ~]$ mkdir -p a/b/c/d/e/f/g/h [user@machine ~]$ tree a a `-- b `-- c `-- d `-- e `-- f `-- g `-- h [user@machine ~]$ mkdir -p a/{b/{b1,b2,b3},c,d}/e/f/g/h [user@machine ~]$ tree a a |-- b | |-- b1 | | `-- e | | `-- f | | `-- g | | `-- h | |-- b2 | | `-- e | | `-- f | | `-- g | | `-- h | |-- b3 | | `-- e | | `-- f | | `-- g | | `-- h | `-- c | `-- d | `-- e | `-- f | `-- g | `-- h |-- c | `-- e | `-- f | `-- g | `-- h `-- d `-- e `-- f `-- g `-- h 32 directories, 0 files Give it a try. you can figure out how does "mkdir -p" works. tree command is used display the directory structure. |
While rsync obviously is way less work, if you want to try 'mkdir' then at least do something like
Code:
ssh user@destination; cd /target/directory; ssh user@source 'cd /source/directory; find ./* -type d'|xargs -iX mkdir -p 'X' |
Hi,
Thanks for the replies. rsync worked out any issues. Quote:
Unspawn, your solution worked similar to rsync. combination of multiple commands was nice. RaviTezu thanks for replying and pointing to -p option in mkdir. It shall be tough for me to compare each and every sub directories and create the same structure as number of sub directories is huge and i can commit errors while creating also. Best Wishes, KJ. |
All times are GMT -5. The time now is 08:46 PM. |