2

I've been using rsync to synchronise folders and it works well. The problem is that more recently I've started syncing folders with larger files in them, and it takes much longer than I'd like it to (due to its hashing comparison). I've noticed that the cp commands can do one part of rsyncs job much quicker, by invoking the -u option. This means newer files in the source can be added to the destination easily using this method.

But what I need to figure out is the second part of the rsync job which I find useful. This is a command which can recursively compare the list of files in all folders, and delete those which no longer feature in the source, but which are still in the destination (but without performing a hash on all the files, a simple comparison using the ls command, for example, is good enough for what I want).

Is this possible?

2 Answers2

0

You can refer this link this link. rsync is having the feature of deleting the folder which doesn't exits on the live ENV.

rsync -av --delete

AReddy
  • 3,172
  • 5
  • 36
  • 76
0

This will (pretend to) delete any differences between the folders:

diff -awr folderA folderB | sed 's/Only in //;s/: /\//' | while read f; do echo "removing ${f}"; done;

If you want to remove differences in A but not B, you can add in a grep like so:

diff -awr folderA folderB | sed 's/Only in //;s/: /\//' | grep "^folderA/" | while read f; do echo "removing ${f}"; done;

note that you have to type folderA into the command twice for this one

To run it for real, just replace echo "removing ${f}"; with rm -f "${f}";

ajlowndes
  • 278