Wednesday, February 27, 2013

Copy Directory Structure without Files in Linux

If you want to copy the directory structure without any files, you can use following command.
rsync -av --include '*/' --exclude '*' /path/source/dir /path/destination/dir
'rsync' gives you utility to copy directory with files or without files.

If you want to copy the directory structure without any files from one host to another. You can use
rsync -av --include '*/' --exclude '*' /path/source/dir user@host:/path/destination/dir
Examples:
Suppose I want to copy the directory structure of /etc in /root/tmp on same host.
rsync -av --include '*/' --exclude '*' /etc /root/tmp
It will copy all directories of /etc in the /root/tmp without any files.
It will not create directory etc in the /root/tmp. It will start from sub-directories of etc.

No comments:

Post a Comment