25

I have the following tree

# upper letters = directory
# lower letters = files
A
|-- B
|-- C
    |-- D
    |-- e <= file
|-- F
    |-- G

I need to copy this tree to another destination, recursively ignoring all the empty directories. So the destination ends up looking like:

C
|-- e

How would you do this with unix, rsync, etc?

37

Of course minutes later I discover an easy method. rsync has a --prune-empty-dirs option.

| improve this answer | |
1

There are various solutions to this problem (Taken from this web page):

This option uses the mkdir command with the find command. This method also requires that you be inside the source folder while executing the command.

bash$ cd /path/to/source && find . -type d -exec mkdir -p /path/to/dest/{} ;

Using find and cpio

bash$ find /path/to/source -type d | cpio -pd /path/to/dest/

Using Rsync

bash$ rsync -a --include '*/' --exclude '*' /path/to/source /path/to/dest

OR

bash$ rysnc -a -f"+ */" -f"- *" /path/to/source /path/to/dest

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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