{"id":576,"date":"2011-02-23T20:19:30","date_gmt":"2011-02-24T01:19:30","guid":{"rendered":"http:\/\/www.shainmiley.com\/wordpress\/?p=576"},"modified":"2011-02-23T20:22:07","modified_gmt":"2011-02-24T01:22:07","slug":"recursive-search-and-copy-while-keeping-the-directory-structure-intact","status":"publish","type":"post","link":"https:\/\/www.shainmiley.com\/wordpress\/2011\/02\/23\/recursive-search-and-copy-while-keeping-the-directory-structure-intact\/","title":{"rendered":"Recursive search and copy while keeping the directory structure intact."},"content":{"rendered":"<p>I recently needed to write a script that would search for a certain pattern in a file name and then copy that file from one directory to another. \u00c2\u00a0If you use the &#8216;find&#8217; command with the standard parameters you will end up with all the files matching the pattern, being placed into a single folder. <\/p>\n<p>\u00c2\u00a0In this case I needed the find command to maintain the directory structure (and create the folders if necessary) once a file matching the pattern was found.<\/p>\n<p>The key to making this happen was to use the &#8216;&#8211;parent&#8217; flag with find. \u00c2\u00a0Here is an example of the command I ended up using:<\/p>\n<pre id=\"terminal\"> find . -wholename \"*search\/pattern*\" -exec cp -p --parent '{}' \/new\/folder\/ ';'<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I recently needed to write a script that would search for a certain pattern in a file name and then copy that file from one directory to another. \u00c2\u00a0If you use the &#8216;find&#8217; command with the standard parameters you will end up with all the files matching the pattern, being placed into a single folder. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/posts\/576"}],"collection":[{"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/comments?post=576"}],"version-history":[{"count":18,"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/posts\/576\/revisions"}],"predecessor-version":[{"id":593,"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/posts\/576\/revisions\/593"}],"wp:attachment":[{"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/media?parent=576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/categories?post=576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/tags?post=576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}