{"id":147,"date":"2008-07-13T11:10:42","date_gmt":"2008-07-13T19:10:42","guid":{"rendered":"http:\/\/www.curlybrace.com\/words\/?p=147"},"modified":"2008-10-07T14:58:04","modified_gmt":"2008-10-07T22:58:04","slug":"organizing-files-by-date-using-find","status":"publish","type":"post","link":"https:\/\/www.curlybrace.com\/words\/2008\/07\/organizing-files-by-date-using-find\/","title":{"rendered":"Organizing Files by Date Using Find"},"content":{"rendered":"<p>I had taken pictures using a friend&#8217;s SD card.  He copied all the files to my flash drive, but this left me without a nice, tidy directory structure.  Normally, I organize my photos like:<\/p>\n<blockquote>\n<pre>2008\r\n   2008_06_27\r\n   2008_06_28\r\n   2008_06_29<\/pre>\n<\/blockquote>\n<p>First off, I needed to list the files by date:<\/p>\n<blockquote>\n<pre>ls -lt<\/pre>\n<\/blockquote>\n<p>This showed me that I had files from the 27th, 28th, and 29th in a single directory.  So I created a directory for each date.<\/p>\n<p>Next, I used <tt>find<\/tt> with the <tt>-newer<\/tt> and <tt>-exec<\/tt> switches to execute a move command on each file newer than a particular file.<\/p>\n<p>By looking at the <tt>ls -lt<\/tt> output, I found the last photo taken on each day.  IMG_6369.JPG was the last taken on the 28th, and IMG_6284.JPG was the last taken on the 27th.<\/p>\n<p>To move all of the files taken on the 28th and 29th, I used this command:<\/p>\n<blockquote>\n<pre>find . -type f -newer IMG_6284.JPG -exec mv {} 2008_06_28 \\;<\/pre>\n<\/blockquote>\n<p>Now, all files taken after the 27th are located in the 2008_06_28 directory.  Now, I change into that directory, and execute:<\/p>\n<blockquote>\n<pre>find . -type f -newer IMG_6369.JPG -exec mv {} ..\/2008_06_29 \\;<\/pre>\n<\/blockquote>\n<p>Now I&#8217;m left with all the photos from the 27th in the main directory.  Those could easily be moved with:<\/p>\n<blockquote>\n<pre>find . -maxdepth 1 -type f -exec mv {} ..\/2008_06_27 \\;<\/pre>\n<\/blockquote>\n<p>I&#8217;m sure there is a quicker, cleaner way to do this, but for the limited number of subdirectories I had to filter into, this was reasonably efficient.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had taken pictures using a friend&#8217;s SD card. He copied all the files to my flash drive, but this left me without a nice, tidy directory structure. Normally, I organize my photos like: 2008 2008_06_27 2008_06_28 2008_06_29 First off, &hellip; <a href=\"https:\/\/www.curlybrace.com\/words\/2008\/07\/organizing-files-by-date-using-find\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[193,15],"tags":[],"class_list":["post-147","post","type-post","status-publish","format-standard","hentry","category-scripting","category-technology"],"_links":{"self":[{"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/comments?post=147"}],"version-history":[{"count":1,"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":367,"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/posts\/147\/revisions\/367"}],"wp:attachment":[{"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}