0

I have a file tree that looks as such:

in
├── file1
├── dir1
└── dir2
    ├── dir3
    │   ├──── file2
    │   └──── junk1
    ├── junk2
    └── junk3

I want to create a sibling of in which looks like the following:

out
├── file1
├── dir1
└── dir2
    └─── dir3
         └── file2

In other words, recursively copy in to out excluding in/dir2 but including in/dir2/dir3/file2.

I have tried the following:

rsync -a --exclude='in/dir2' --include='in/dir2/dir3/file2' in out

Which results in the following:

out
└── in
    └── file1

So I tried the following:

rsync -a --exclude='dir2' --include='dir2/dir3/file2' in/ out

Which results in:

out
└── file1

How can I achieve what I want with rsync or other unix tools? I would prefer to stay away from using weird methods like piping tar into tar...

0

What about breaking this up into more than one rsync command and bundle them into a shell script.

Another possible alternative is a combination of find with cpio to the destination device.

1
  • Not exactly what I wanted but I guess it works.
    – knpwrs
    Feb 12 '13 at 22:01
1

You can explore the --exclude-from=FILE and --include-from=FILE options with rsync.

--include-from=FILE
        This  option is related to the --include option, but it specifies a FILE that contains include patterns
        (one per line).  Blank lines in the file and lines starting with ’;’ or ’#’ are ignored.  If FILE is -,
        the list will be read from standard input.

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.