{"id":1328,"date":"2012-10-05T13:09:09","date_gmt":"2012-10-05T13:09:09","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=1328"},"modified":"2012-10-05T13:11:06","modified_gmt":"2012-10-05T13:11:06","slug":"copying-directory-trees-with-rsync","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=1328","title":{"rendered":"Copying directory trees with rsync"},"content":{"rendered":"<p>You can use cp -a to copy directory trees, but rsync can do the same and give you more flexibility. rsync supports a syntax for filter rules which specify which files and directories should and should not be copied.<\/p>\n<p>Examples<\/p>\n<p>Copy only the directory structure without copying any files:<\/p>\n<p>&nbsp;<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">rsync -a -f&quot;+ *\/&quot; -f&quot;- *&quot; source\/ destination\/<\/div><\/div>\n<p>&nbsp;<\/p>\n<p>The two -f arguments mean, respectively, &#8220;copy all directories&#8221; and then &#8220;do not copy anything else&#8221;.<\/p>\n<p>&nbsp;<\/p>\n<p>Copy only directories and Python files:<\/p>\n<p>&nbsp;<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">rsync -a -f&quot;+ *\/&quot; -f&quot;+ *.py&quot; -f&quot;- *&quot; source\/ destination\/<\/div><\/div>\n<p>&nbsp;<\/p>\n<p>This is really handy for replicating the general directory structure but only copying a subset of the files.<\/p>\n<p>&nbsp;<\/p>\n<p>Copy everything but exclude .git directories:<\/p>\n<p>&nbsp;<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">rsync -a -f&quot;- .git\/&quot; -f&quot;+ *&quot; source\/ destination\/<\/div><\/div>\n<p>&nbsp;<\/p>\n<p>Conclusion<\/p>\n<p>&nbsp;<\/p>\n<p>Of course, rsync also works great for copying files between machines, and it knows better than to transfer files that already exist on the destination. I use something similar to the above to do backups, copying my homedir but excluding stuff like caches that are not even worth copying.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can use cp -a to copy directory trees, but rsync can do the same and give you more flexibility. rsync supports [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1328","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1328","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1328"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1328\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}