{"id":1565,"date":"2021-09-23T12:58:41","date_gmt":"2021-09-23T07:28:41","guid":{"rendered":"http:\/\/www.webhostingchennai.co.in\/blog\/?p=1553"},"modified":"2021-10-06T14:39:38","modified_gmt":"2021-10-06T09:09:38","slug":"15-useful-rsync-commands-in-linux","status":"publish","type":"post","link":"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/","title":{"rendered":"15 useful rsync Commands in Linux"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#15_useful_rsync_commands_in_Linux\" >15 useful rsync commands in Linux<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#1Copy_or_Sync_files_locally_rsync_-zvh\" >1.Copy or Sync files locally (rsync -zvh)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#2Copy_or_Sync_directory_locally_rsync_-zavh\" >2.Copy or Sync directory locally (rsync -zavh)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#3Copy_files_directories_recursively_locally_rsync_-zrvh_or_rsync_-zavh\" >3.Copy files &amp; directories recursively locally (rsync -zrvh or rsync -zavh)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#4Copy_or_sync_files_and_directories_from_local_to_remote_system\" >4.Copy or sync files and directories from local to remote system<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#5Copy_or_Sync_files_and_directories_from_remote_machine_to_local_system\" >5.Copy or Sync files and directories from remote machine to local system<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#6Specify_remote_shell_during_synchronization_rsync_-e_ssh\" >6.Specify remote shell during synchronization (rsync -e ssh)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#7Display_Synchronization_progress_in_rsync_command_output\" >7.Display Synchronization progress in rsync command output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#8Copy_the_directory_structure_without_copying_files\" >8.Copy the directory structure without copying files<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#9Resume_large_file_transfer_after_getting_failed_in_scp\" >9.Resume large file transfer after getting failed in scp<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#10Delete_files_at_destination_if_it_is_not_present_in_source_%E2%80%93delete\" >10.Delete files at destination if it is not present in source (\u2013delete)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#11Put_limit_on_file_transfer_size_%E2%80%93max-size\" >11.Put limit on file transfer size (\u2013max-size)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#12Do_not_synccopy_the_modified_file_at_destination\" >12.Do not sync\/copy the modified file at destination<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#13Remove_files_from_source_after_synchronization_%E2%80%93remove-source-files\" >13.Remove files from source after synchronization (\u2013remove-source-files)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#14Dry_run_rsync_command_before_actual_synchronization\" >14.Dry run rsync command before actual synchronization<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#15Include_and_Exclude_files_during_synchronization_with_rsync\" >15.Include and Exclude files during synchronization with rsync<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#16Put_restriction_on_data_transfer_speed_in_rsync_%E2%80%93bwlimit\" >16.Put restriction on data transfer speed in rsync (\u2013bwlimit=&lt;KB\/s&gt;)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/chennaiwebhosting.in\/blog\/15-useful-rsync-commands-in-linux\/#17View_the_difference_in_files_directories_between_source_and_destination\" >17.View the difference in files &amp; directories between source and destination<\/a><\/li><\/ul><\/nav><\/div>\n<h4><span class=\"ez-toc-section\" id=\"15_useful_rsync_commands_in_Linux\"><\/span>15 useful rsync commands in Linux<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>rsync command is used to sync (copy) files and directories locally and remotely. The important feature of rsync command is that it works on \u201cdelta transfer algorithm\u201d, which means it will only sync or copy the changes from source to destination instead of copying the whole file which ultimately reduce amount of data sent over network.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1648 size-full\" src=\"http:\/\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/15rsync.jpg\" alt=\"15 useful rsync commands in Linux\" width=\"640\" height=\"260\" \/><\/p>\n<p>Linux geeks generally use rsync command to manage day to day backup, mirroring, and restoration activities. It uses remote shell like SSH while synchronizing the files from local machine to remote machine and any user in the system can use rsync command as it does not require root or sudo privileges..<\/p>\n<p>Here, we will discuss some useful rsync command examples in Linux, these examples will help specially Linux beginners to manage their sync, mirroring, and backup task more efficiently.<\/p>\n<p>Rsync command is available for all UNIX and Linux operating systems. When we do minimal installation of <a href=\"https:\/\/www.centos.org\/\" rel=\"nofollow noopener\" target=\"_blank\">CentOS<\/a> &amp; RHEL OS then rsync package is not part of default installation, so to install rsync on CentOS &amp; RHEL, run the under yum command<\/p>\n<pre># yum install rsync -y<\/pre>\n<p>In Debian operating Systems (Ubuntu &amp; Linux Mint) use below apt command to install rysnc tool.<\/p>\n<pre># apt install rsync -y<\/pre>\n<p><span style=\"text-decoration: underline;\"><strong>Syntax of rsync command:<\/strong><\/span><\/p>\n<p><strong>Local Sync:<\/strong><\/p>\n<pre># rsync {options} {Source} {Destination}<\/pre>\n<p><strong>Remote Sync pull:<\/strong><\/p>\n<pre> # rsync {options} &lt;User_Name&gt;@&lt;Remote-Host&gt;:&lt;Source-File-Dir&gt; &lt;Destination&gt;<\/pre>\n<p><strong>Remote Sync Push:<\/strong><\/p>\n<pre> # rsync &lt;Options&gt; &lt;Source-Files-Dir&gt; &lt;User_Name&gt;@&lt;Remote-Host&gt;:&lt;Destination&gt;<\/pre>\n<p>Some of the commonly used options in rsync command are listed below:<\/p>\n<p>[table id=2 \/]<\/p>\n<p>Let\u2019s jump into the useful examples of rsync command<\/p>\n<h4><span class=\"ez-toc-section\" id=\"1Copy_or_Sync_files_locally_rsync_-zvh\"><\/span>1.Copy or Sync files locally (rsync -zvh)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Let\u2019s assume we want to copy a file from webhostc user\u2019s home directory to \/opt\/back folder, execute the below rsync command<\/p>\n<pre>[root@webhostc ~]# rsync -zvh \/home\/webhostc\/OpenStack-Networking.pdf \/opt\/backup\r\nOpenStack-Networking.pdf\r\nsent 4.09M bytes\u00a0 received 35 bytes\u00a0 2.73M bytes\/sec\r\ntotal size is 6.15M\u00a0 speedup is 1.50\r\n[root@webhostc ~]#<\/pre>\n<p>In above we have used the options like -z for compression, -v for verbose output and -h for human readable output.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"2Copy_or_Sync_directory_locally_rsync_-zavh\"><\/span>2.Copy or Sync directory locally (rsync -zavh)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Let\u2019s assume we want to copy or sync webhostc user\u2019s home directory to \/opt\/backup folder, execute\u00a0 the below rsync command with options <strong>-zavh<\/strong>,<\/p>\n<pre>[root@webhostc ~]# rsync -zavh \/home\/webhostc \/opt\/backup\r\nsending incremental file list\r\nwebhostc\/\r\nwebhostc\/.bash_logout\r\nwebhostc\/.bash_profile\r\nwebhostc\/.bashrc\r\nwebhostc\/OpenStack-Networking.pdf\r\n\r\nsent 4.09M bytes\u00a0 received 96 bytes\u00a0 8.19M bytes\/sec\r\ntotal size is 6.15M\u00a0 speedup is 1.50\r\n[root@webhostc ~]#<\/pre>\n<p>Let\u2019s verify whether directory is copied or not, execute below command,<span id=\"ezoic-pub-ad-placeholder-131\" class=\"ezoic-adpicker-ad\"><\/span><\/p>\n<pre>[root@webhostc ~]# ls -ld \/opt\/backup\/*\r\n-rwx------. 1 root\u00a0\u00a0 root\u00a0\u00a0 6153239 Apr\u00a0 7 00:25 \/opt\/backup\/OpenStack-Networking.pdf\r\ndrwx------. 2 webhostc webhostc \u00a0\u00a0\u00a0\u00a0 90 Apr\u00a0 7 00:25 \/opt\/backup\/webhostc\r\n[root@webhostc ~]#&lt;span id=&quot;ezoic-pub-ad-placeholder-130&quot; class=&quot;ezoic-adpicker-ad&quot;&gt;&lt;\/span&gt;<\/pre>\n<div id=\"google_ads_iframe_\/1254144,87031940\/linuxtechi_com-banner-1_0__container__\"><\/div>\n<p>As we can see \u201cwebhostc\u201d directory is created on destination folder and its contents are also copied. In the above example if use trail \/ after source folder (\/home\/webhostc\/) then rsync command will not create webhostc directory on destination but it will copy the contents only.<\/p>\n<pre>[root@webhostc ~]# rsync -zavh \/home\/webhostc\/ \/opt\/backup<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"3Copy_files_directories_recursively_locally_rsync_-zrvh_or_rsync_-zavh\"><\/span>3.Copy files &amp; directories recursively locally (rsync -zrvh or rsync -zavh)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Let\u2019s assume we have multiple files and directories inside webhostc user home directory, use below rsync command to copy files and directories recursively, either use -a or -r option to copy files and directories recursively.<\/p>\n<p><strong>Note<\/strong> : In rsync command\u00a0<strong>-a <\/strong>option\u00a0is used for archiving during the copy or sync and apart from archiving -a option is also used for followings:<\/p>\n<ul>\n<li>recursively copy files and directory<\/li>\n<li>copy symlinks as symlinks<\/li>\n<li>preserve permissions<\/li>\n<li>preserve group<\/li>\n<li>preserve modification time<\/li>\n<li>preserve ownership<\/li>\n<\/ul>\n<pre>[root@webhostc ~]# rsync -zrvh \/home\/webhostc \/opt\/backup\r\nor\r\n[root@webhostc ~]# rsync -zavh \/home\/webhostc \/opt\/backup\r\n<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"4Copy_or_sync_files_and_directories_from_local_to_remote_system\"><\/span>4.Copy or sync files and directories from local to remote system<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Let\u2019s suppose we want to copy the folder \u201c<strong>\/home\/webhostc\/techi<\/strong>\u201d from local machine to remote machine (192.168.1.2) under the \/opt<\/p>\n<pre>[root@gateway ~]# rsync -zarvh \/home\/webhostc\/tech root@192.168.1.2:\/opt\r\nroot@192.168.1.2&#039;s password:\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\r\ntech\/OTRS\/\r\ntech\/OTRS\/Database-Selection-OTRS-Installation-CentOS7.jpg\r\ntech\/OTRS\/Install-OTRS-Accept-License.png\r\ntech\/OTRS\/Install-OTRS-CentOS7-RHEL7.jpg\r\ntech\/OTRS\/mysql-secure-installation-centos7-part2.jpg\r\n\r\nsent 34.85M bytes\u00a0 received 2.65K bytes\u00a0 6.34M bytes\/sec\r\ntotal size is 37.77M\u00a0 speedup is 1.08\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\r\n[root@webhostc ~]#<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"5Copy_or_Sync_files_and_directories_from_remote_machine_to_local_system\"><\/span>5.Copy or Sync files and directories from remote machine to local system<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Let\u2019s suppose we want to copy files and directories from remote machine(192.168.1.2) to our local system, in the below example I am copying remote folder <strong>\u201c\/opt\/rpms_db<\/strong>\u201d in my local machine under <strong>\/tmp<\/strong> folder<\/p>\n<pre>[root@webhostc ~]# rsync -zarvh root@192.168.1.2:\/opt\/rpms_db \/tmp\r\nroot@192.168.1.2&#039;s password:\r\nreceiving incremental file list\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\r\nrpms_db\/\r\nrpms_db\/httpd-2.4.6-88.el7.centos.x86_64.rpm\r\nrpms_db\/httpd-tools-2.4.6-88.el7.centos.x86_64.rpm\r\nrpms_db\/postfix-2.10.1-7.el7.x86_64.rpm\r\nrpms_db\/pytalloc-2.1.13-1.el7.x86_64.rpm\r\nrpms_db\/samba-4.8.3-4.el7.x86_64.rpm\r\nrpms_db\/samba-client-libs-4.8.3-4.el7.x86_64.rpm\r\nrpms_db\/samba-common-4.8.3-4.el7.noarch.rpm\r\nrpms_db\/samba-common-libs-4.8.3-4.el7.x86_64.rpm\r\nrpms_db\/samba-common-tools-4.8.3-4.el7.x86_64.rpm\r\nrpms_db\/samba-libs-4.8.3-4.el7.x86_64.rpm\r\n\r\nsent 484 bytes\u00a0 received 15.45M bytes\u00a0 1.07M bytes\/sec\r\ntotal size is 16.37M\u00a0 speedup is 1.06\r\n[root@webhostc ~]#<\/pre>\n<p>Above command will automatically create a folder \u201crpms_db\u201d under the \/tmp folder in our local machine.<\/p>\n<pre>[root@webhostc ~]# ls -l \/tmp\/\r\ntotal 8\r\n-rwx------. 1 root root\u00a0 827 Apr\u00a0 6 12:54 ks-script-avmuxw\r\ndrwxr-xr-x. 2 root root 4096 Apr\u00a0 7 01:42 rpms_db\r\n-rw-------. 1 root root\u00a0\u00a0\u00a0 0 Apr\u00a0 6 12:35 yum.log\r\n[root@webhostc ~]# ls -l \/tmp\/rpms_db\/\r\ntotal 16028\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\r\n-rw-r--r--. 1 root root 2844028 Nov 12 09:28 httpd-2.4.6-88.el7.centos.x86_64.rpm\r\n-rw-r--r--. 1 root root\u00a0\u00a0 92504 Nov 12 09:28 httpd-tools-2.4.6-88.el7.centos.x86_64.rpm\r\n-rw-r--r--. 1 root root 2558136 Nov 12 09:44 postfix-2.10.1-7.el7.x86_64.rpm\r\n-rw-r--r--. 1 root root\u00a0\u00a0 17404 Nov 12 09:44 pytalloc-2.1.13-1.el7.x86_64.rpm\r\n-rw-r--r--. 1 root root\u00a0 696472 Nov 12 09:46 samba-4.8.3-4.el7.x86_64.rpm\r\n-rw-r--r--. 1 root root 5070800 Nov 12 09:46 samba-client-libs-4.8.3-4.el7.x86_64.rpm\r\n-rw-r--r--. 1 root root\u00a0 210984 Nov 12 10:19 samba-common-4.8.3-4.el7.noarch.rpm\r\n-rw-r--r--. 1 root root\u00a0 167512 Nov 12 09:46 samba-common-libs-4.8.3-4.el7.x86_64.rpm\r\n-rw-r--r--. 1 root root\u00a0 458380 Nov 12 09:46 samba-common-tools-4.8.3-4.el7.x86_64.rpm\r\n-rw-r--r--. 1 root root\u00a0 282332 Nov 12 09:46 samba-libs-4.8.3-4.el7.x86_64.rpm\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\r\n[root@webhostc ~]#<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"6Specify_remote_shell_during_synchronization_rsync_-e_ssh\"><\/span>6.Specify remote shell during synchronization (rsync -e ssh)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>In rsync command we can specify the remote shell like ssh during synchronization, let\u2019s assume we want to use secure communication between source to destination machine via rsync then we should use ssh as remote shell, example is shown below<\/p>\n<pre>[root@webhostc ~]# rsync -zarvh -e ssh\u00a0 root@192.168.1.2:\/opt\/rpms_db\u00a0 \/tmp\r\nroot@192.168.1.2&#039;s password:\r\nreceiving incremental file list\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\r\nrpms_db\/\r\nrpms_db\/httpd-2.4.6-88.el7.centos.x86_64.rpm\r\nrpms_db\/httpd-tools-2.4.6-88.el7.centos.x86_64.rpm\r\nrpms_db\/postfix-2.10.1-7.el7.x86_64.rpm\r\nrpms_db\/pytalloc-2.1.13-1.el7.x86_64.rpm\r\nrpms_db\/samba-4.8.3-4.el7.x86_64.rpm\r\nrpms_db\/samba-client-libs-4.8.3-4.el7.x86_64.rpm\r\nrpms_db\/samba-common-4.8.3-4.el7.noarch.rpm\r\nrpms_db\/samba-common-libs-4.8.3-4.el7.x86_64.rpm\r\nrpms_db\/samba-common-tools-4.8.3-4.el7.x86_64.rpm\r\nrpms_db\/samba-libs-4.8.3-4.el7.x86_64.rpm\r\n\r\nsent 484 bytes\u00a0 received 15.45M bytes\u00a0 1.82M bytes\/sec\r\ntotal size is 16.37M\u00a0 speedup is 1.06\r\n[root@webhostc ~]#<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"7Display_Synchronization_progress_in_rsync_command_output\"><\/span>7.Display Synchronization progress in rsync command output<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>If you want to see the sync or copy progress in rsync command then use \u201c<strong>\u2013progress<\/strong>\u201c, example is shown below<\/p>\n<pre>[root@webhostc ~]# rsync -avh --progress root@192.168.1.2:\/opt\/rpms_db \/tmp\r\nroot@192.168.1.2&#039;s password:\r\nreceiving incremental file list\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026..\r\nrpms_db\/\r\nrpms_db\/httpd-2.4.6-88.el7.centos.x86_64.rpm\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2.84M 100%\u00a0\u00a0 35.22MB\/s\u00a0\u00a0\u00a0 0:00:00 (xfr#6, to-chk=18\/25)\r\nrpms_db\/httpd-tools-2.4.6-88.el7.centos.x86_64.rpm\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 92.50K 100%\u00a0\u00a0\u00a0 1.13MB\/s\u00a0\u00a0\u00a0 0:00:00 (xfr#7, to-chk=17\/25)\r\nrpms_db\/postfix-2.10.1-7.el7.x86_64.rpm\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2.56M 100%\u00a0\u00a0 14.44MB\/s\u00a0\u00a0\u00a0 0:00:00 (xfr#17, to-chk=7\/25)\r\nrpms_db\/samba-4.8.3-4.el7.x86_64.rpm\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 696.47K 100%\u00a0\u00a0\u00a0 3.71MB\/s\u00a0\u00a0\u00a0 0:00:00 (xfr#19, to-chk=5\/25)\r\nrpms_db\/samba-client-libs-4.8.3-4.el7.x86_64.rpm\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 5.07M 100%\u00a0\u00a0 19.90MB\/s\u00a0\u00a0\u00a0 0:00:00 (xfr#20, to-chk=4\/25)\r\nrpms_db\/samba-common-4.8.3-4.el7.noarch.rpm\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 210.98K 100%\u00a0 844.42kB\/s\u00a0\u00a0\u00a0 0:00:00 (xfr#21, to-chk=3\/25)\r\nrpms_db\/samba-common-libs-4.8.3-4.el7.x86_64.rpm\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 167.51K 100%\u00a0 667.70kB\/s\u00a0\u00a0\u00a0 0:00:00 (xfr#22, to-chk=2\/25)\r\nrpms_db\/samba-common-tools-4.8.3-4.el7.x86_64.rpm\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 458.38K 100%\u00a0\u00a0\u00a0 1.77MB\/s\u00a0\u00a0\u00a0 0:00:00 (xfr#23, to-chk=1\/25)\r\nrpms_db\/samba-libs-4.8.3-4.el7.x86_64.rpm\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 282.33K 100%\u00a0\u00a0\u00a0 1.09MB\/s\u00a0\u00a0\u00a0 0:00:00 (xfr#24, to-chk=0\/25)\r\n\r\nsent 484 bytes\u00a0 received 16.38M bytes\u00a0 3.64M bytes\/sec\r\ntotal size is 16.37M\u00a0 speedup is 1.00\r\n[root@gateway ~]#<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"8Copy_the_directory_structure_without_copying_files\"><\/span>8.Copy the directory structure without copying files<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>There are some scenarios where we want to copy the directory structure skiping files only from local machine to remote or vice versa.<\/p>\n<p>Let\u2019s suppose we want to copy the directory structure of \u201c\/home\/webhostc\u201d from local machine to remote machine (192.168.1.2) under \/opt folder.<span id=\"ezoic-pub-ad-placeholder-132\" class=\"ezoic-adpicker-ad\"><\/span><\/p>\n<pre>root@webhostc ~]# rsync -av -f&quot;+ *\/&quot; -f&quot;- *&quot; \/home\/webhostc root@192.168.1.2:\/opt\/\r\nroot@192.168.1.2&#039;s password:\r\nbuilding file list ... done\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\r\nwebhostc\/\r\n\r\nsent 43 bytes\u00a0 received 19 bytes\u00a0 17.71 bytes\/sec\r\ntotal size is 0\u00a0 speedup is 0.00\r\n[root@webhostc ~]#<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"9Resume_large_file_transfer_after_getting_failed_in_scp\"><\/span>9.Resume large file transfer after getting failed in scp<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>There are some scenarios in linux admin profile where we have started copying a larger file using scp command, but it got terminated in the middle and we can\u2019t afford to start copying it again using scp because of its large size and time consumption.<\/p>\n<p><span id=\"div-gpt-ad-linuxtechi_com-leader-2-0\" class=\"ezoic-ad ezfound\" data-google-query-id=\"CK_en8jBlPMCFT-GZgIdIL0KxQ\"><\/span>So in this situation rsync command can used as it \u00a0can start copying the file from where it left off or terminated, or in other words rsync can transfer the files which are partially copied using scp command. Example is shown below,<\/p>\n<pre>[root@webhostc ~]# scp root@192.168.1.2:\/root\/ubuntu-18.04-desktop-amd64.iso \/opt\r\nroot@192.168.1.2&#039;s password:\r\nubuntu-18.04-desktop-amd64.iso\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 28%\u00a0 526MB\u00a0 61.5MB\/s\u00a0\u00a0 00:21 ETA\r\n^CKilled by signal 2.\r\n[root@gateway ~]#\r\n[root@gateway ~]# rsync -P --rsh=ssh root@192.168.1.2:\/root\/ubuntu-18.04-desktop-amd64.iso \/opt\r\nroot@192.168.1.29&#039;s password:\r\nubuntu-18.04-desktop-amd64.iso\r\n\u00a0 1,921,843,200 100%\u00a0\u00a0 18.47MB\/s\u00a0\u00a0\u00a0 0:01:39 (xfr#1, to-chk=0\/1)\r\n[root@webhostc ~]#<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"10Delete_files_at_destination_if_it_is_not_present_in_source_%E2%80%93delete\"><\/span>10.Delete files at destination if it is not present in source (\u2013delete)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>If you have already synced files from source to destination and from source you have deleted the files then you can force rsync command to delete the files on destination using the \u2013delete option, example is shown below<span id=\"ezoic-pub-ad-placeholder-134\" class=\"ezoic-adpicker-ad\"><\/span><\/p>\n<pre>[root@webhostc ~]# rsync -avz --delete \/opt\/rpms_db root@192.168.1.2:\/tmp\/rpms_db\r\nroot@192.168.1.2&#039;s password:\r\nsending incremental file list\r\ndeleting rpms_db\/apr-util-1.5.2-6.el7.x86_64.rpm\r\ndeleting rpms_db\/apr-1.4.8-3.el7_4.1.x86_64.rpm\r\nrpms_db\/\r\n\r\nsent 862 bytes\u00a0 received 105 bytes\u00a0 276.29 bytes\/sec\r\ntotal size is 15,947,152\u00a0 speedup is 16,491.37\r\n[root@webhostc ~]#<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"11Put_limit_on_file_transfer_size_%E2%80%93max-size\"><\/span>11.Put limit on file transfer size (\u2013max-size)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>If you don\u2019t want to transfer or copy the large files using rsync then use the option \u2018\u2013<strong>max-size={specify-size-here}\u2019<\/strong>, let\u2019s assume we don\u2019t we don\u2019t want to transfer the files whose size is more than 500K,<span id=\"ezoic-pub-ad-placeholder-135\" class=\"ezoic-adpicker-ad\"><\/span><\/p>\n<p>Note: To specify the size in MB use M and for GB use G.<\/p>\n<pre>[root@webhostc ~]# rsync -avz --max-size=&#039;500K&#039; \/opt\/rpms_db root@192.168.1.2:\/tmp<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"12Do_not_synccopy_the_modified_file_at_destination\"><\/span>12.Do not sync\/copy the modified file at destination<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>There are some scenarios where we modified the files at destination and we don\u2019t want to overwrite the modified files from source while syncing, so this can be easily achieved using <strong>-u<\/strong> option in rsync command<span id=\"ezoic-pub-ad-placeholder-136\" class=\"ezoic-adpicker-ad\"><\/span><\/p>\n<div id=\"google_ads_iframe_\/1254144,87031940\/linuxtechi_com-large-mobile-banner-2_0__container__\"><\/div>\n<pre>[root@webhostc ~]# rsync -avzu root@192.168.1.2:\/opt\/techi \/home\/webhostc\/tech\r\nroot@192.168.1.2&#039;s password:\r\nreceiving incremental file list\r\n\r\nsent 37 bytes\u00a0 received 4,960 bytes\u00a0 1,427.71 bytes\/sec\r\ntotal size is 37,771,649\u00a0 speedup is 7,558.87\r\n[root@webhostc ~]#<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"13Remove_files_from_source_after_synchronization_%E2%80%93remove-source-files\"><\/span>13.Remove files from source after synchronization (\u2013remove-source-files)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Let\u2019s suppose you want to delete files from source once the synchronization is completed using rsync command. In the below example, folder from local system \u201c<strong>\/home\/webhostc\/techi.tgz<\/strong>\u201d is synced to remote system (192.168.1.29), once the synchronization is completed, it will delete the file from source.<span id=\"ezoic-pub-ad-placeholder-137\" class=\"ezoic-adpicker-ad\"><\/span><\/p>\n<pre>[root@webhostc ~]# rsync --remove-source-files -zvh \/home\/webhostc\/tech.tgz root@192.168.1.3:\/opt\r\nroot@192.168.1.3&#039;s password:\r\ntechi.tgz\r\nsent 597 bytes\u00a0 received 43 bytes\u00a0 182.86 bytes\/sec\r\ntotal size is 518\u00a0 speedup is 0.81\r\n[root@webhostc ~]#\r\n[root@webhostc ~]# ls -l \/home\/webhostc\/tech.tgz\r\nls: cannot access \/home\/webhostc\/tech.tgz: No such file or directory\r\n[root@webhostc ~]#<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"14Dry_run_rsync_command_before_actual_synchronization\"><\/span>14.Dry run rsync command before actual synchronization<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>There can be some situations where we are not about behavior of rsync command so in such cases it is better to do dry run of rsync<span id=\"ezoic-pub-ad-placeholder-138\" class=\"ezoic-adpicker-ad\"><\/span><\/p>\n<pre>[root@webhostc ~]# rsync --dry-run --remove-source-files -zvh \/home\/webhostc\/backup.tar.gz\u00a0 root@192.168.1.29:\/opt\r\nroot@192.168.1.2&#039;s password:\r\nprojects.tar\r\n\r\nsent 51 bytes\u00a0 received 19 bytes\u00a0 7.37 bytes\/sec\r\ntotal size is 981.24M\u00a0 speedup is 14,017,682.29 (DRY RUN)\r\n[root@webhostc ~]#<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"15Include_and_Exclude_files_during_synchronization_with_rsync\"><\/span>15.Include and Exclude files during synchronization with rsync<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>There are some situations where we want to copy or sync files &amp; directories of specific type and want to exclude files or directories of specific type. Rsync command supports both include and exclude options.<span id=\"ezoic-pub-ad-placeholder-139\" class=\"ezoic-adpicker-ad\"><\/span><\/p>\n<p>In the below example want to copy the files of type pdf and rpm and exclude png file types.<\/p>\n<pre>[root@webhostc ~]# rsync -avz -e ssh --include &#039;*.pdf *.rpm&#039; --exclude &#039;*.png&#039; \/home\/webhostc\/tech root@192.168.1.2:\/opt\r\nroot@192.168.1.2&#039;s password:\r\nsending incremental file list\r\ntech\/\r\ntech\/OpenStack-Networking.pdf\r\ntech\/httpd-2.4.6-88.el7.centos.x86_64.rpm\r\ntech\/httpd-tools-2.4.6-88.el7.centos.x86_64.rpm\r\ntech\/postfix-2.10.1-7.el7.x86_64.rpm\r\n\r\nsent 9,469,912 bytes\u00a0 received 96 bytes\u00a0 2,705,716.57 bytes\/sec\r\ntotal size is 11,647,907\u00a0 speedup is 1.23\r\n[root@webhostc ~]#<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"16Put_restriction_on_data_transfer_speed_in_rsync_%E2%80%93bwlimit\"><\/span>16.Put restriction on data transfer speed in rsync (\u2013bwlimit=&lt;KB\/s&gt;)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>In rsync command we can set the bandwidth limit for data transfer from one machine to another, use \u2018<strong>\u2013bwlimit=&lt;KB\/S&gt;<\/strong>\u2018 option in rsync command to put limit on data transfer speed.<\/p>\n<p><span id=\"div-gpt-ad-linuxtechi_com-mobile-leaderboard-1-0\" class=\"ezoic-ad ezfound\" data-google-query-id=\"CK6zwsnBlPMCFX6NZgIdWzME_Q\"><\/span>Let\u2019s assume we want to set maximum data transfer rate (speed) is 600 KB\/s with rsync, example is shown below<\/p>\n<pre>[root@webhostc ~]# rsync -avz --progress --bwlimit=600 \/home\/webhostc\/tech root@192.168.1.2:\/opt\r\nroot@192.168.1.2&#039;s password:\r\nsending incremental file list\r\ntech\/\r\ntech\/OpenStack-Networking.pdf 6,153,239 100%\u00a0 910.02kB\/s\u00a0\u00a0\u00a0 0:00:06 (xfr#1, to-chk=6\/8)\r\ntech\/httpd-2.4.6-88.el7.centos.x86_64.rpm2,844,028 100%\u00a0 615.28kB\/s\u00a0\u00a0\u00a0 0:00:04 (xfr#2, to-chk=5\/8)\r\ntech\/httpd-tools-2.4.6-88.el7.centos.x86_64.rpm 92,504 100%\u00a0 507.51kB\/s\u00a0\u00a0\u00a0 0:00:00 (xfr#3, to-chk=4\/8)\r\ntech\/webhostc-2.png 0 100%\u00a0\u00a0\u00a0 0.00kB\/s\u00a0\u00a0\u00a0 0:00:00 (xfr#4, to-chk=3\/8)\r\ntech\/webhostc-3.png0 100%\u00a0\u00a0\u00a0 0.00kB\/s\u00a0\u00a0\u00a0 0:00:00 (xfr#5, to-chk=2\/8)\r\ntech\/webhostc.png0 100%\u00a0\u00a0\u00a0 0.00kB\/s\u00a0\u00a0\u00a0 0:00:00 (xfr#6, to-chk=1\/8)\r\ntech\/postfix-2.10.1-7.el7.x86_64.rpm2,558,136 100%\u00a0 594.80kB\/s\u00a0\u00a0\u00a0 0:00:04 (xfr#7, to-chk=0\/8)\r\n\r\nsent 9,470,087 bytes\u00a0 received 153 bytes\u00a0 485,653.33 bytes\/sec\r\ntotal size is 11,647,907\u00a0 speedup is 1.23\r\n[root@webhostc ~]#<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"17View_the_difference_in_files_directories_between_source_and_destination\"><\/span>17.View the difference in files &amp; directories between source and destination<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Use \u201c<strong>-i<\/strong>\u201d option in rsync command to list the difference in files and directories between source and destination. Example is shown below<\/p>\n<pre>[root@webhostc ~]# rsync -avzi \/home\/webhostc\/tech root@192.168.1.2:\/opt\r\nroot@192.168.1.2&#039;s password:\r\nsending incremental file list\r\n.d..t...... tech\/\r\n&lt;f.st...... tech\/acctlist.txt\r\n\r\nsent 438 bytes\u00a0 received 45 bytes\u00a0 138.00 bytes\/sec\r\ntotal size is 11,648,064\u00a0 speedup is 24,116.07\r\n[root@webhostc ~]#<\/pre>\n<p><span id=\"div-gpt-ad-linuxtechi_com-mobile-leaderboard-2-0\" class=\"ezoic-ad ezfound\" data-google-query-id=\"CNSysMjBlPMCFSSgZgIdTkMB-A\"><\/span>As per above command output, there is difference in file called \u201cacctlist.txt\u201d on destination. Following are the meaning of the keywords in above output,<\/p>\n<ul>\n<li>d: indicates change in destination file<\/li>\n<li>f: indicates a file<\/li>\n<li>t: indicates change in timestamps<\/li>\n<li>s: indicates change in size<\/li>\n<\/ul>\n<p>That\u2019s all from this blog, in case these examples you to understand rsync command more efficiently then please do share your feedback and comments<\/p>\n<p>To know about &#8216;find&#8217; command for linux, <a href=\"https:\/\/chennaiwebhosting.in\/blog\/find-command-in-linux\/\">Click Here<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>15 useful rsync commands in Linux rsync command is used to sync (copy) files and directories locally and remotely. The important feature of rsync command is that it works on \u201cdelta transfer algorithm\u201d, which means it will only sync or copy the changes from source to destination instead of copying the whole file which ultimately [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1672,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[57,14,13,11],"tags":[90,91,92,93,94],"class_list":["post-1565","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos-redhat","category-centos-6-rhel-6","category-centos-7-rhel-7","category-linux","tag-15-rsync-commands","tag-commands-for-rsync","tag-rsync-commands","tag-transfer-command","tag-useful-rsync-commands"],"_links":{"self":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=1565"}],"version-history":[{"count":1,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1565\/revisions"}],"predecessor-version":[{"id":1673,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1565\/revisions\/1673"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/media\/1672"}],"wp:attachment":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=1565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=1565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=1565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}