Thursday, April 26, 2012

How to copy directories alone from one directory to other


find . -type d  -depth | cpio -dumpl "Target directory path"
-depth : Always true. Causes descent of the directory hierarchy to  be  done  so  that  all entries in a directory are acted on before the directory  itself.   This  can  be useful  when  find  is  used  with cpio(1) to transfer files that are contained in directories without  write
permission.

cpio: copy files to or from archives.
Options : d : Creating a leading directories when needed.
              u : Unconditional
             m : preserve time, modifications
               l : link files
              p : In copy-out mode, cpio copies files into an archive. It reads a list of filenames, one per line, on the standard input, and writes the archive onto the standard output. A typical way to generate the list of filenames is with the find command; you should give find the -depth option to minimize problems with permissions on directories that are unreadable.