Sync two local folders in bash
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Beneath the City Looping
--
Chapters
00:00 Sync Two Local Folders In Bash
00:19 Answer 1 Score 16
00:54 Answer 2 Score 0
01:10 Accepted Answer Score 27
01:34 Answer 4 Score 0
01:47 Thank you
--
Full question
https://superuser.com/questions/409980/s...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux
#avk47
ACCEPTED ANSWER
Score 27
There are many more properties to rsync than the previous answer mentions. You should look into them yourself:
man rsync
But for your problem I'd suggest:
rsync -a --delete X Y
This way, the receiver (Y) will delete any file it has that is not in X. Be sure you do it right though. Used incorrectly as root can easily kill your system... :)
ANSWER 2
Score 16
Take a look at rsync(1). It's intended to do pretty much exactly what you want.
rsync -av X Y
It supports remote copying, through its own protocol or ssh, but it can also be used locally.
Depending on the exact behaviour you want you may also want to pass the --update
option. This will tell rsync not to overwrite files which already exist on the target and are newer than the ones in the source.
If you want to remove extra files (i.e. files which exist in Y, but not in X) you can add the --delete
option.
ANSWER 3
Score 0
Try using rsnyc, possibly with the following command:
rsync -avzu /home/x /y
-u
= do not overwrite a file at the destination, if it is modified
ANSWER 4
Score 0
I think some of the functionality that you are looking for in option -u (update) actually exists in this option:
"--ignore-existing" - skip updating files that exist on receiver