Copy directory structure from one location to another without files

Suppose that I have a directory with name xyz under /opt and I want to copy same directory structure (without files under it) to /mnt with directory name pqr.

Following is the directory structure containing sub-directories and files.

/opt/xyz/
├── dir1
│   ├── f1
│   │   └── file2
│   └── file1
├── dir2
│   └── f2
│       ├── f3
│       └── file3
└── dir3
    └── f4
        ├── f5
        │   └── file5
        └── file4

Command is:

#rsync -a --include '*/' --exclude '*' /opt/xyz/ /mnt/pqr
or
#cd /opt/xyz && find . -type d -exec mkdir -p /mnt/pqr/{} \;

After executing one of the above command we will get same directory structure without files as below.

/mnt/pqr/
├── dir1
│   └── f1
├── dir2
│   └── f2
│       └── f3
└── dir3
    └── f4
        └── f5

Reference Link: how to copy the directory structure without the files in linux






1 comment: