{"id":112,"date":"2021-02-08T09:03:01","date_gmt":"2021-02-08T09:03:01","guid":{"rendered":"https:\/\/webhostingnoida.in\/blog\/?p=112"},"modified":"2021-09-01T09:04:07","modified_gmt":"2021-09-01T09:04:07","slug":"how-to-use-rsync-to-sync-local-directories","status":"publish","type":"post","link":"https:\/\/webhostingnoida.in\/blog\/how-to-use-rsync-to-sync-local-directories\/","title":{"rendered":"How To Use Rsync To Sync Local Directories"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 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-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/webhostingnoida.in\/blog\/how-to-use-rsync-to-sync-local-directories\/#Introduction\" >Introduction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/webhostingnoida.in\/blog\/how-to-use-rsync-to-sync-local-directories\/#What_Is_Rsync\" >What Is Rsync?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/webhostingnoida.in\/blog\/how-to-use-rsync-to-sync-local-directories\/#Basic_Syntax\" >Basic Syntax<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/webhostingnoida.in\/blog\/how-to-use-rsync-to-sync-local-directories\/#An_Important_Note\" >An Important Note<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 id=\"introduction\" class=\"has-luminous-vivid-orange-color has-text-color\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span>Introduction<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><em>Rsync<\/em>, which stands for \u201cremote sync\u201d, is a remote and local file synchronization tool. It uses an algorithm that minimizes the amount of data copied by only moving the portions of files that have changed.<\/p>\n<h2 id=\"what-is-rsync\" class=\"has-luminous-vivid-orange-color has-text-color\"><span class=\"ez-toc-section\" id=\"What_Is_Rsync\"><\/span>What Is Rsync?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Rsync is a very flexible network-enabled syncing tool. Due to its ubiquity on Linux and Unix-like systems and its popularity as a tool for system scripts, it is included on most Linux distributions by default.<\/p>\n<h2 id=\"basic-syntax\" class=\"has-luminous-vivid-orange-color has-text-color\"><span class=\"ez-toc-section\" id=\"Basic_Syntax\"><\/span>Basic Syntax<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The basic syntax of\u00a0<code>rsync<\/code>\u00a0is very straightforward, and operates in a way that is similar to ssh, scp, and cp.<\/p>\n<p>We will create two test directories and some test files with the following commands:<\/p>\n<pre class=\"wp-block-code\"><code>cd ~\r\nmkdir dir1\r\nmkdir dir2\r\ntouch dir1\/file{1..100}\r\n<\/code><\/pre>\n<p>We now have a directory called\u00a0<code>dir1<\/code>\u00a0with 100 empty files in it.<\/p>\n<pre class=\"wp-block-code\"><code>ls dir1\r\n<\/code><\/pre>\n<figure class=\"wp-block-image size-full\"><\/figure>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-113\" src=\"https:\/\/webhostingnoida.in\/blog\/wp-content\/uploads\/2021\/09\/vps1-300x72.png\" alt=\"\" width=\"955\" height=\"229\" srcset=\"https:\/\/webhostingnoida.in\/blog\/wp-content\/uploads\/2021\/09\/vps1-300x72.png 300w, https:\/\/webhostingnoida.in\/blog\/wp-content\/uploads\/2021\/09\/vps1-768x184.png 768w, https:\/\/webhostingnoida.in\/blog\/wp-content\/uploads\/2021\/09\/vps1.png 1014w\" sizes=\"auto, (max-width: 955px) 100vw, 955px\" \/><\/p>\n<p>We also have an empty directory called\u00a0<code>dir2<\/code>.<\/p>\n<p>To sync the contents of\u00a0<code>dir1<\/code>\u00a0to\u00a0<code>dir2<\/code>\u00a0on the same system, type:<\/p>\n<pre class=\"wp-block-code\"><code>rsync -r dir1\/ dir2\r\n<\/code><\/pre>\n<p>Lets list the dir2 and see whether the files copied to directory<\/p>\n<pre class=\"wp-block-code\"><code>ls dir2<\/code><\/pre>\n<figure class=\"wp-block-image size-large is-resized\"><\/figure>\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-105\" src=\"https:\/\/webhostingnoida.in\/blog\/wp-content\/uploads\/2021\/07\/csf2-300x54.png\" alt=\"\" width=\"978\" height=\"176\" srcset=\"https:\/\/webhostingnoida.in\/blog\/wp-content\/uploads\/2021\/07\/csf2-300x54.png 300w, https:\/\/webhostingnoida.in\/blog\/wp-content\/uploads\/2021\/07\/csf2.png 578w\" sizes=\"auto, (max-width: 978px) 100vw, 978px\" \/><\/h3>\n<h3 id=\"an-important-note\" class=\"has-luminous-vivid-orange-color has-text-color\"><span class=\"ez-toc-section\" id=\"An_Important_Note\"><\/span>An Important Note<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You may have noticed that there is a trailing slash (<code>\/<\/code>) at the end of the first argument in the above command.<\/p>\n<p>This is necessary to mean \u201cthe contents of\u00a0<code>dir1<\/code>\u201d. The alternative, without the trailing slash, would place\u00a0<code>dir1<\/code>, including the directory, within\u00a0<code>dir2<\/code>. This would create a hierarchy that looks like:<\/p>\n<pre class=\"wp-block-code\"><code>~\/dir2\/dir1\/[files]<\/code><\/pre>\n<p>Always double-check your arguments before executing an rsync command.<\/p>\n<p>We hope you\u2019ve found this useful!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Rsync, which stands for \u201cremote sync\u201d, is a remote and local file synchronization tool. It uses an algorithm that minimizes the amount of data copied by only moving the portions of files that have changed. What Is Rsync? Rsync is a very flexible network-enabled syncing tool. Due to its ubiquity on Linux and Unix-like<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-112","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/posts\/112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/comments?post=112"}],"version-history":[{"count":1,"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/posts\/112\/revisions"}],"predecessor-version":[{"id":114,"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/posts\/112\/revisions\/114"}],"wp:attachment":[{"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/media?parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/categories?post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/tags?post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}