1

I want to use rsync to merge these multiple folders together into one folder. Each folder contains unique file names so there are no conflicts in terms of filenames.

My folders are the following structure currently:

Project
  -Folder 1
    -File 1
  -Folder 2
    -File 2
  -Folder 3
    -File 3

Project 1
  -Folder 1
    -File 4
  -Folder 2
    -File 5

Project 2
  -Folder 3
    -File 6

Project 3
  -Folder 4
    -File 7
  -Folder 5
    -File 8

I want to achieve the following:

Project 
Folder 1
  -File 1
  -File 4
Folder 2
  -File 2
  -File 5
Folder 3
  -File 3
  -File 6
Folder 4
  -File 7
Folder 5
  -File 8

1 Answer 1

0

I haven't tested it, but you might try --max-delete=0 as an option to experiment with. There are obvious challenges (e.g. if your source directory deletes a file, it will never get deleted on the target).

In your position, I would seriously consider either scp instead of rsync (if you are only doing one transfer), or creating a parallel directory using hard links.

This would look something like the following (again, experiment and test; I haven't run any of these commands in a while):

From your working / sync directory:

rsync --inplace A/Project ./Project    # Perform all of the syncs
rsync --inplace B/Project1 ./Project1
rsync --inplace C/Project2 ./Project2
rsync --inplace D/Project3 ./Project3
mkdir -p /tmp/combination/Project      # Create the destination dir if needed.
rm -r /tmp/combination/Project/*       # Clean it out of old cruft.
cp -l */* /tmp/combination/Project/    # Create hard links at the correct scope.

Your desired output should then be in /tmp/combination/Project, and it should be updated to current by running all of the above commands a second time.

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.