{"id":16,"date":"2014-02-01T15:52:00","date_gmt":"2014-02-01T15:52:00","guid":{"rendered":""},"modified":"2016-02-25T18:09:01","modified_gmt":"2016-02-25T18:09:01","slug":"how-to-use-find-and-rsync-to-copy-a-bunch-of-files-to-a-local-or-remote-destination","status":"publish","type":"post","link":"https:\/\/www.root42.de\/blog\/?p=16","title":{"rendered":"How to use find and rsync to copy a bunch of files to a local or remote destination"},"content":{"rendered":"<p>I use rsync a lot. And I use find a lot. You can use them both together, by using the magnificent xargs command. Two problems are there to solve: xargs usually just pastes the arguments from find at the end of the specified command. No way to specify the destination directory. Second, file names with spaces are a problem.<\/p>\n<p>The solutions are:<\/p>\n<ul>\n<li>The -print0 option of find uses 0-bytes to separate results, instead of spaces and newlines<\/li>\n<li>The -0 option of xargs tells xargs to look for said 0-bytes<\/li>\n<li>The -J option of xargs allows us to tell xargs where to put the file names that we feed to it.<\/li>\n<\/ul>\n<p>So let&#8217;s put it together:<\/p>\n<div style=\"background-color: black; color: whitesmoke; font-size: 14px;\"><span style=\"font-family: Courier New, Courier, monospace;\"><span style=\"color: #34bd26;\">pi@raspberrypi<\/span> <span style=\"color: #5330e1;\">~ $<\/span> find . -name &#8216;your*pattern.jpg&#8217; -print0 | xargs -J % -0 rsync -aP % user@host:some\/dir\/<\/span><\/div>\n<p>Thanks to <a href=\"http:\/\/www.redeyeblind.com\/post\/48271055922\/rsync-and-xargs-files-with-spaces\">redeyeblind<\/a> for the insightful blog post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I use rsync a lot. And I use find a lot. You can use them both together, by using the magnificent xargs command. Two problems are there to solve: xargs usually just pastes the arguments from find at the end of the specified command. No way to specify the destination directory. Second, file names with &hellip; <a href=\"https:\/\/www.root42.de\/blog\/?p=16\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to use find and rsync to copy a bunch of files to a local or remote destination&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,5,3,16,10],"tags":[],"_links":{"self":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/16"}],"collection":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16"}],"version-history":[{"count":1,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/16\/revisions"}],"predecessor-version":[{"id":200,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/16\/revisions\/200"}],"wp:attachment":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}