rsync Ubuntu
Using Rsync to Sync Local System
his puts folder A into folder B:
rsync -avu --delete "/home/user/A" "/home/user/B"
If you want the contents of folders A and B to be the same, put /home/user/A/
(with the slash) as the source. This takes not the folder A but all of its content and puts it into folder B. Like this:
rsync -avu --delete "/home/user/A/" "/home/user/B"
-a
Do the sync preserving all filesystem attributes-v
run verbosely-u
only copy files with a newer modification time (or size difference if the times are equal)--delete
delete the files in target folder that do not exist in the source
Manpage: https://download.samba.org/pub/rsync/rsync.html
src = https://unix.stackexchange.com/questions/203846/how-to-sync-two-folders-with-command-line-tools
Using Rsync to Sync with a Remote System
To use rsync
to sync with a remote system, you only need SSH access configured between your local and remote machines, as well as rsync
installed on both systems. Once you have SSH access verified between the two machines, you can sync the dir1
folder from the previous section to a remote machine by using the following syntax. Please note in this case, that you want to transfer the actual directory, so you’ll omit the trailing slash:
rsync -a ~/dir1 username@remote_host:destination_directory
#OR
rsync -a -e 'ssh -p 2320' ~/dir1 username@remote_host:destination_directory
This process is called a push operation because it “pushes” a directory from the local system to a remote system. The opposite operation is pull, and is used to sync a remote directory to the local system. If the dir1
directory were on the remote system instead of your local system, the syntax would be the following:
rsync -a username@remote_host:/home/username/dir1 place_to_sync_on_local_machine
Like cp
and similar tools, the source is always the first argument, and the destination is always the second.
src :