rsync command for synchronizing files from a source to a destination

Directories/Files existing in the same machine or VM we can use the below command

rsync -av --progress /home/username1/source_directory/ /home/username2/destination_directory/

rsync - command
-a - archive
-v - increase verbosity
--progress - show progress during transfer
/home/username1/source_directory/ - Location where source files or folder exist
/home/username2/destination_directory/ - Location where the files need to be synced

Directories/Files existing in the two different machines or VM we can use the below command

rsync -avz /home/username1/source_directory/ [email protected]:/home/username2/destination_directory/

rsync - command
-a - archive
-v - increase verbosity
-z - compress
--progress - show progress during transfer
/home/username1/source_directory/ - Location where source files or folders exist
[email protected]:/home/username2/destination_directory/ - Location where the files need to be synced with server IP and user name



Note
-a, --archive
    This is equivalent to -rlptgoD. It is a quick way of saying you want recursion and want to preserve almost everything (with -H being a notable omission). The only exception to the above equivalence is when --files-from is specified, in which case -r is not implied.