{"id":564,"date":"2010-12-06T09:58:52","date_gmt":"2010-12-06T14:58:52","guid":{"rendered":"http:\/\/www.jaimerios.com\/?p=564"},"modified":"2010-12-06T09:58:52","modified_gmt":"2010-12-06T14:58:52","slug":"using-dterm-and-the-shell-to-rename-files","status":"publish","type":"post","link":"https:\/\/jaimerios.com\/?p=564","title":{"rendered":"Using DTerm and the shell to rename files"},"content":{"rendered":"<p>I download files from my bank that have some really long name to them and at the end of the name, is the date. <\/p>\n<p>The date is not formatted, of course, and I wanted to rename the files easily, without manually parsing out the string. <\/p>\n<p>Now on my computer, I have <a href=\"http:\/\/www.decimus.net\/dterm.php\" target=\"_blank\" rel=\"noopener\">DTerm<\/a> and <a href=\"http:\/\/macromates.com\/\" target=\"_blank\" rel=\"noopener\">TextMate<\/a> at my disposal. So, I created a shell script that would take two parameters: the path to the file and the file name to parse:<\/p>\n<pre lang=\"BASH\">\n#!\/usr\/bin\/env bash\n\necho \"Starting script with parameters $1 $2\"\n\nfull_path=$1\nfile_name=$2\nyear=${file_name:(-12):4}\nmonth=${file_name:(-8):2}\nday=${file_name:(-6):2}\n\ncd $full_path\nmv $file_name \"${year}-${month}-${day}_statement.PDF\"\n<\/pre>\n<p>Now that I saved the script in my Documents folder, I can go to where my file is downloaded and type:<br \/>\n<code>\/Users\/jaimerios\/Documents\/rename_file.sh \"$PWD\" mysuperlongfilename20101014.PDF<\/code><\/p>\n<p>To make things easier, I use <a href=\"http:\/\/smilesoftware.com\/TextExpander\/\" target=\"_blank\" rel=\"noopener\">TextExpander<\/a> to type out the command for me in DTerm, then hit &#8220;Command+Shift+V&#8221; for DTerm to type out the name of the currently selected file. <\/p>\n<p>Then Voila! The file has been renamed!<\/p>\n<p>References:<br \/>\n<a href=\"http:\/\/tldp.org\/LDP\/abs\/html\/string-manipulation.html\" target=\"_blank\" rel=\"noopener\">http:\/\/tldp.org\/LDP\/abs\/html\/string-manipulation.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I download files from my bank that have some really long name to them and at the end of the name, is the date. The date is not formatted, of course, and I wanted to rename the files easily, without manually parsing out the string. Now on my computer, I have DTerm and TextMate at &#8230; <a title=\"Using DTerm and the shell to rename files\" class=\"read-more\" href=\"https:\/\/jaimerios.com\/?p=564\" aria-label=\"Read more about Using DTerm and the shell to rename files\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[78,176,384,403],"class_list":["post-564","post","type-post","status-publish","format-standard","hentry","category-tip","tag-bash","tag-dterm","tag-rename-files","tag-shell"],"_links":{"self":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=564"}],"version-history":[{"count":0,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/564\/revisions"}],"wp:attachment":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}