{"id":111,"date":"2021-08-16T05:07:03","date_gmt":"2021-08-16T05:07:03","guid":{"rendered":"http:\/\/webhostingpune.co.in\/blog\/?p=111"},"modified":"2021-08-16T05:07:06","modified_gmt":"2021-08-16T05:07:06","slug":"how-to-use-rsync-to-sync-local-directories","status":"publish","type":"post","link":"https:\/\/webhostingpune.co.in\/blog\/how-to-use-rsync-to-sync-local-directories\/","title":{"rendered":"How To Use Rsync to Sync Local Directories"},"content":{"rendered":"\n<h2 class=\"has-luminous-vivid-orange-color has-text-color wp-block-heading\" id=\"introduction\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><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\n\n\n<h2 class=\"has-luminous-vivid-orange-color has-text-color wp-block-heading\" id=\"what-is-rsync\">What Is Rsync?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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\n\n\n<h2 class=\"has-luminous-vivid-orange-color has-text-color wp-block-heading\" id=\"basic-syntax\">Basic Syntax<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The basic syntax of&nbsp;<code>rsync<\/code>&nbsp;is very straightforward, and operates in a way that is similar to ssh, scp, and cp.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We will create two test directories and some test files with the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ~\r\nmkdir dir1\r\nmkdir dir2\r\ntouch dir1\/file{1..100}\r<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We now have a directory called\u00a0<code>dir1<\/code>\u00a0with 100 empty files in it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls dir1\r<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1014\" height=\"243\" src=\"http:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/08\/list.png\" alt=\"\" class=\"wp-image-112\" srcset=\"https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/08\/list.png 1014w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/08\/list-300x72.png 300w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/08\/list-768x184.png 768w\" sizes=\"auto, (max-width: 1014px) 100vw, 1014px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">We also have an empty directory called&nbsp;<code>dir2<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To sync the contents of\u00a0<code>dir1<\/code>\u00a0to\u00a0<code>dir2<\/code>\u00a0on the same system, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -r dir1\/ dir2\r<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Lets list the dir2 and see whether the files copied to directory<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls dir2<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/08\/list2-1024x99.png\" alt=\"\" class=\"wp-image-113\" width=\"850\" height=\"82\" srcset=\"https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/08\/list2-1024x99.png 1024w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/08\/list2-300x29.png 300w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/08\/list2-768x74.png 768w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/08\/list2-1536x148.png 1536w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/08\/list2.png 1721w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/figure>\n\n\n\n<h3 class=\"has-luminous-vivid-orange-color has-text-color wp-block-heading\" id=\"an-important-note\">An Important Note<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">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\n\n\n<p class=\"wp-block-paragraph\">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\n\n\n<pre class=\"wp-block-code\"><code>~\/dir2\/dir1\/&#91;files]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Always double-check your arguments before executing an rsync command.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We hope you\u2019ve found this useful!\u00a0<\/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 systems and its popularity as a tool for system scripts, it is included on most Linux distributions by default. Basic Syntax The basic syntax of&nbsp;rsync&nbsp;is very straightforward, and operates in a way that is similar to ssh, scp, and cp. We will create two test directories and some test files with the following commands: We now have a directory called\u00a0dir1\u00a0with 100 empty files in it. We also have an empty directory called&nbsp;dir2. To sync the contents of\u00a0dir1\u00a0to\u00a0dir2\u00a0on the same system, type: Lets list the dir2 and see whether the files copied to directory An Important Note You may have noticed that there is a trailing slash (\/) at the end of the first argument in the above command. This is necessary to mean \u201cthe contents of\u00a0dir1\u201d. The alternative, without the trailing slash, would place\u00a0dir1, including the directory, within\u00a0dir2. This would create a hierarchy that looks like: Always double-check your arguments before executing an rsync command. We hope you\u2019ve found this useful!\u00a0<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-111","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts\/111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":1,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts\/111\/revisions"}],"predecessor-version":[{"id":114,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts\/111\/revisions\/114"}],"wp:attachment":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}