How do I copy a directory tree but not the files in Linux?

Solution 1:

Just found this:

rsync -a -f"+ */" -f"- *" source/ destination/

http://psung.blogspot.com/2008/05/copying-directory-trees-with-rsync.html

Solution 2:

find some/dir -type d -print0 | rsync --files-from=/dev/stdin -0 ...

Solution 3:

Another approach is with find and mkdir:

find SOURCE -type d -exec mkdir TARGET/{} \;

Just make sure TARGET already exists or use the -p option of mkdir.


Solution 4:

You also can do :

find inputdir -type d | cpio -pdumv destdir

The power of simplicity ;)