I want to copy about 200 directories & subdirectories from one location to another but I don't want to copy the thousands of files within those directories. I am on Linux.

Note: I don't have enough space to copy everything then delete all the files.

link|improve this question

25% accept rate
feedback

4 Answers

find some/dir -type d -print0 | rsync --files-from=/dev/stdin -0 ...
link|improve this answer
feedback
up vote 3 down vote accepted

Just found this:

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

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

link|improve this answer
feedback

You also can do :

find inputdir -type d | cpio -pdumv destdir

The power of simplicity ;)

link|improve this answer
feedback

Similarly, using (GNU) tar:

find some/dir -type d -print |
tar --no-recursion -T- -c -p -f- |
(cd another/dir && tar -x -p -f-)

You don't really need the -print0 on the find command line or the -0 on the rsync command line unless you have filenames that contain newline characters (which is possible but highly unlikely). Tar (and rsync, and cpio) read filenames line-by-line; using a NULL terminator is mostly useful with xargs, which normally reads whitespace separated filenames (and so does not handle files/directories with spaces in their names without -0).

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.