{"id":1222,"date":"2015-11-24T11:54:41","date_gmt":"2015-11-24T17:54:41","guid":{"rendered":"http:\/\/islascruz.org\/blog\/?p=1222"},"modified":"2016-11-29T17:15:35","modified_gmt":"2016-11-29T23:15:35","slug":"how-to-move-some-files-but-preserve-the-directory-tree","status":"publish","type":"post","link":"https:\/\/islascruz.org\/blog\/2015\/11\/24\/how-to-move-some-files-but-preserve-the-directory-tree\/","title":{"rendered":"How to move some files but preserve the directory tree?"},"content":{"rendered":"<p>So, I have a bunch of ogg files that I moved to mp3 (I don&#8217;t want to start a format\/encoder war, I just did it), I wanted to move the old ogg files, I didn&#8217;t delete them because probably I need them in the future. To move the files apart the easiest way could be using find and xargs:<\/p>\n<pre class=\"lang:bash decode:1 \" >\n\nfind . -iname &quot;*ogg&quot; -print0 |xargs -0 -I {} mv {} \/dest\/folder\/\n\n<\/pre>\n<p>The problem with this is that all those ogg files would be in \/dest\/folder\/ all together, and I want to have them each in the corresponding subfolder, I was looking and found that some uses &#8220;cp &#8211;parents&#8221; unfortunately it seems that the cp in OS X does not include that.<\/p>\n<h3>What I ended up doing.<\/h3>\n<p>If you create a package file (.tar for example), the directories are preserved, so, for me the trick was using tar for that purpose.<\/p>\n<pre class=\"lang:bash decode:1 \" >\n\nfind . -name &quot;*ogg&quot; -print0 | xargs -0 tar cvf - |(cd \/dest\/folder\/ ; tar xfp -)\n\n<\/pre>\n<p>You&#8217;ll see all those ogg files in the screen as they are &#8220;copied&#8221; to the destination folder. later you can remove the files with find again.<\/p>\n<pre class=\"lang:bash decode:1 \" >\n\nfind . -iname &quot;*ogg&quot; -delete\n\n<\/pre>\n<p>&nbsp;<\/p>\n<p>I assume there is a way to remove the files as soon as they have been added to the tar file.<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1222\" class=\"pvc_stats all  \" data-element-id=\"1222\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/islascruz.org\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>So, I have a bunch of ogg files that I moved to mp3 (I don&#8217;t want to start a format\/encoder war, I just did it), I wanted to move the old ogg files, I didn&#8217;t delete them because probably I need them in the future. To move the files apart the easiest way could be [&hellip;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1222\" class=\"pvc_stats all  \" data-element-id=\"1222\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/islascruz.org\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":6363,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[238,182,143,34,184,139],"class_list":["post-1222","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-personal","tag-automation","tag-bash","tag-linux","tag-tips","tag-tricks","tag-unix"],"brizy_media":[],"_links":{"self":[{"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/posts\/1222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/comments?post=1222"}],"version-history":[{"count":5,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/posts\/1222\/revisions"}],"predecessor-version":[{"id":3128,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/posts\/1222\/revisions\/3128"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/media\/6363"}],"wp:attachment":[{"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/media?parent=1222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/categories?post=1222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/tags?post=1222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}