{"id":9,"date":"2014-08-21T19:20:20","date_gmt":"2014-08-21T19:20:20","guid":{"rendered":"https:\/\/www.tech.shinynewthings.com\/?p=9"},"modified":"2014-08-21T20:26:31","modified_gmt":"2014-08-21T20:26:31","slug":"cpio-ftw","status":"publish","type":"post","link":"https:\/\/www.tech.shinynewthings.com\/?p=9","title":{"rendered":"Copy Folder Structure and Selected Files"},"content":{"rendered":"<p>When working on a project last year, I had to migrate and sets of derivative images and associated text files from an internal server to a development server. The project requirements included the retention of the existing folder structure of any folders that contained a few extensions but did not require all of the files contained in the folders. I knew I could use rsync but wanted to see if there were other commands that would achieve the same result.<\/p>\n<p>Using the find command below from the origin directory, I was able to recursively find all folders that contained, the required files. For the example, I&#8217;ve only included .jpg and .txt but this could easily be extended. -iname is included to indicate that the extension should be case insensitive.<\/p>\n<address>$ find . -iname *.jpg -or -iname *.txt\u00a0<\/address>\n<p>The simple solution to migrating the files is a unix command on your mac.<\/p>\n<address>$ cpio<\/address>\n<p>CPIO is a utility that archives files and their existing structure.In copy-pass mode, <b>cpio<\/b> copies files and their folder structure without archiving. The options are described below.<\/p>\n<p><em>p indicates pass through mode <\/em><\/p>\n<p><em>d makes directories<\/em><\/p>\n<p><em>m preserves modification time <\/em><\/p>\n<p><em>u replaces files unconditionally<\/em><\/p>\n<p>Below is the combined find and cpio command which pipes the result of the find to cpio.<\/p>\n<address>$ find . -iname *.jpg -or -iname *.txt | <span class=\"il\">cpio<\/span> -pdmu \/newServer\/newFolder\/<\/address>\n<p>Simple, fast one line bash awesomeness.<\/p>\n<p>Check this page for\u00a0<a title=\"for more info on cpio\" href=\"http:\/\/www.computerhope.com\/unix\/ucpio.htm\" target=\"_blank\">more info about cpio.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When working on a project last year, I had to migrate and sets of derivative images and associated text files from an internal server to a development server. The project requirements included the retention of the existing folder structure of any folders that contained a few extensions but did not require all of the files [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9"}],"version-history":[{"count":4,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":14,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions\/14"}],"wp:attachment":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}