{"id":561,"date":"2014-10-17T10:46:18","date_gmt":"2014-10-17T14:46:18","guid":{"rendered":"http:\/\/devolve.net\/blog\/?p=561"},"modified":"2015-05-21T10:06:31","modified_gmt":"2015-05-21T14:06:31","slug":"machine-readable-dates","status":"publish","type":"post","link":"https:\/\/www.devolve.local\/machine-readable-dates\/","title":{"rendered":"Machine-readable Dates"},"content":{"rendered":"

I had some directories named in the format of “Jul 18, 2012”. Thanks, iPhoto export, but no thanks.<\/p>\n

\/bin\/ls | while read dirnam; do \r\n  echo \"$dirnam\" | grep -Eq '^\\w{3} \\d{1,2}, \\d{4}$'\r\n  if [ $? -eq 0 ]; then \r\n    newdir=`gdate -d \"$dirnam\" +%F`\r\n    mv -i \"$dirnam\" \"$newdir\"\r\n  fi\r\ndone<\/pre>\n

Note: gdate is GNU date after doing homebrew install coreutils<\/code>.
\n<\/p>\n

Update:<\/strong><\/p>\n

Some of the directories created where in the form “Jul 18, 2012-2”. In order to rename those as well I ran a subsequent command (don’t run this before the first invocation above – I don’t know how that will turn out):<\/p>\n

\/bin\/ls | while read dirnam; do \r\n  echo \"$dirnam\" | grep -Eq '^\\w{3} \\d{1,2}, \\d{4}'\r\n  if [ $? -eq 0 ]; then \r\n    newdir=`gdate -d \"${dirnam%-2}\" +%F`\r\n    mv -i \"${dirnam}\" \"${newdir}-2\"\r\n  fi\r\ndone<\/pre>\n","protected":false},"excerpt":{"rendered":"

I had some directories named in the format of “Jul 18, 2012”. Thanks, iPhoto export, but no thanks. \/bin\/ls | while read dirnam; do echo “$dirnam” | grep -Eq ‘^\\w{3} \\d{1,2}, \\d{4}$’ if [ $? -eq 0 ]; then newdir=`gdate -d “$dirnam” +%F` mv -i “$dirnam” “$newdir” fi done Note: gdate is GNU date after […]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[34,41,15,26],"_links":{"self":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts\/561"}],"collection":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/comments?post=561"}],"version-history":[{"count":5,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts\/561\/revisions"}],"predecessor-version":[{"id":566,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts\/561\/revisions\/566"}],"wp:attachment":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/media?parent=561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/categories?post=561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/tags?post=561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}