Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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...

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

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.

share|improve this answer
    
Not exactly what I wanted but I guess it works. –  KPthunder Feb 12 '13 at 22:01
add comment

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.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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