1

I need to create a deploy script to combine the following directory structure:

├── LIB_COMMON
│   ├── file1.php 
│   ├── file2.php
│   ├── file3.php
│   └── file4.php
├── LIB_CZ
│   ├── file2.php
│   ├── file3.php
│   ├── file5.php
│   └── file6.php

...which result should look like:

├── LIB_RESULT
│   ├── file1.php ...with content from LIB_COMMON
│   ├── file2.php ...from LIB_CZ
│   ├── file3.php ...from LIB_CZ
│   ├── file4.php ...from LIB_COMMON
│   ├── file5.php ...from LIB_CZ
│   └── file6.php ...from LIB_CZ

One way to do it is:

rsync LIB_COMMON/ LIB_RESULT/ --delete-after
rsync LIB_CZ/ LIB_RESULT/

...but this will always transfer many files.

Other way could be:

cp LIB_COMMON/ TMP/ 
cp LIB_CZ/ TMP/
rsync TMP/ LIB_RESULT/ --delete-after

So, Does anyone know an elegant way to achieve this?

Thushi
  • 9,498

3 Answers3

2
rsync -avz LIB_COMMON/ LIB_CZ/ LIB_RESULT/ --delete-after

This will sync the content of lib_common/ & lib_cz/ to the lib_result/ folder.

slm
  • 369,824
Ray BSD
  • 161
  • 6
    Welcome to Stack Exchange!  While this may answer the question, it would be a better answer if you could explain why it does so.  We (on Unix&Linux, at least) are looking for comprehensive, high-quality answers that provide some explanation and context.  Don’t just give a one-line answer; explain why your answer is right, ideally with citations.  Answers that don’t include explanations may be removed. – G-Man Says 'Reinstate Monica' May 28 '15 at 23:01
0

works for me in other order

~/test$ ll a/
-rw-r--r-- 1 jakub jakub   18 Jun  8 10:19 file1
-rw-r--r-- 1 jakub jakub    0 Jun  8 10:18 file2
-rw-r--r-- 1 jakub jakub    0 Jun  8 10:18 file3

~/test$ ll b/
-rw-r--r-- 1 jakub jakub    0 Jun  8 10:18 file2
-rw-r--r-- 1 jakub jakub   13 Jun  8 10:19 file3
-rw-r--r-- 1 jakub jakub    0 Jun  8 10:18 file4

~/test$ ll c/
-rw-r--r-- 1 jakub jakub    0 Jun  8 10:22 file5

~/test$ rsync -avz b/ a/ c/ --delete-after
building file list ... done
./
file1
file2
file3
file4
deleting file5

sent 345 bytes  received 94 bytes  878.00 bytes/sec
total size is 31  speedup is 0.07

~/test$ ll c/
-rw-r--r-- 1 jakub jakub   18 Jun  8 10:19 file1
-rw-r--r-- 1 jakub jakub    0 Jun  8 10:18 file2
-rw-r--r-- 1 jakub jakub   13 Jun  8 10:19 file3
-rw-r--r-- 1 jakub jakub    0 Jun  8 10:18 file4
-2

This answer to a different question helped: https://stackoverflow.com/a/22558474/652971

Here's how I would do this:

rsync $(
 find ./one/ -type f $(printf "! -name %s " `ls ./two/`)
 find ./two/ -type f 
) user@remote:/path/