2

at the moment I am struggling to find a solution to include only files in a subdirectory but exclude all other stuff. File structure looks like this

$ tree ../
../
├── from
│   ├── a
│   │   ├── aa
│   │   │   └── x.txt
│   │   ├── a.txt
│   │   └── b.txt
│   └── b
│       ├── b.txt
│       └── c.txt
└── to

and only the stuff in a/aa/ shall be transferred into to/.

$ rsync -avh --include=a/aa/*** --exclude=* ../from/ ../to/

does not work and to/ stays empty but doing this with a/

$ rsync -avh --include=a/*** --exclude=* ../from/ ../to/

it works

$ tree ../
..
├── from
│   ├── a
│   │   ├── aa
│   │   │   └── x.txt
│   │   ├── a.txt
│   │   └── b.txt
│   └── b
│       ├── b.txt
│       └── c.txt
└── to
    └── a
        ├── aa
        │   └── x.txt
        ├── a.txt
        └── b.txt

but there a.txt and b.txt should not be there. What did I miss?

Thanks for your help.

1
  • There might be a way to do that with --include and --exclude; I'm not sure. But wouldn't mkdir -p ../to/aa/a && rsync -avh ../from/aa/a/ ../to/aa/a/ be easier?
    – frabjous
    May 14, 2022 at 19:00

1 Answer 1

1

In your first command, a/aa/*** would match aa/ and anything after that, but there is no match for a/, so nothing is copied.

In the second command, a/*** matches a/ and anything after that, so you copy more than just a/aa/ contents.

For example, this should be enough:

rsync -avh --include='/a/' --include='/a/aa/***' --exclude='*' from/ to/

man rsync to INCLUDE/EXCLUDE PATTERN RULES

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .