{"id":419,"date":"2011-01-28T00:30:38","date_gmt":"2011-11-08T13:51:50","guid":{"rendered":"http:\/\/kraftek.com\/blog\/recursive-scripting-in-bash\/"},"modified":"2011-01-28T00:30:38","modified_gmt":"2011-11-08T13:51:50","slug":"recursive-scripting-in-bash","status":"publish","type":"post","link":"\/blog\/index.php\/recursive-scripting-in-bash\/","title":{"rendered":"recursive scripting in bash"},"content":{"rendered":"<p>Needed to rename all directories and files in a deep directory structure to remove spaces and ugly characters in their<br \/>\nnames, in order to build a playlist, take a look at this recursive bash shell:<br \/>\n#!\/usr\/bin\/bash<br \/>\nDIR=\/200gb\/MP3<br \/>\nFTYPE=mp3<br \/>\nrenamedir ()<br \/>\n{<br \/>\ncd<br \/>\nfind . -type d -maxdepth 1 -name &#8220;??*&#8221; | while read d; do<br \/>\nDN=`echo &#8220;$d&#8221; | sed &#8220;s\/&amp;\/And\/g;s\/-\/\/g;s\/ \/\/g;s\/(\/\/g;s\/)\/\/g;s\/[\/<br \/>\n\/g;s\/]\/\/g;s\/&#8217;\/\/g&#8221; | tr -s &#8216;_&#8217;`<br \/>\nif [ &#8220;$d&#8221; != &#8220;$DN&#8221; ];then<br \/>\necho &#8220;&#8212; `pwd` $d&#8221;<br \/>\nmv &#8220;$d&#8221; $DN<br \/>\nfi<br \/>\nrenamedir<br \/>\n$DN<br \/>\ncd ..<br \/>\ndone<br \/>\n}<br \/>\necho &#8221; &#8212;- Recursively clean directories&#8221;<br \/>\nrenamedir $DIR<br \/>\necho &#8221; &#8212;- Now clean files&#8221;<br \/>\ncd $DIR<br \/>\nfind . -type f -iname &#8220;*.$FTYPE&#8221; | while read f;do<br \/>\nFN=`echo &#8220;$f&#8221;| sed &#8220;s\/&amp;\/And\/g;s\/-\/\/g;s\/ \/\/g;s\/(\/\/g;s\/)\/\/g;s\/[\/\/g;s\/]\/<br \/>\n\/g;s\/&#8217;\/\/g&#8221; | tr -s &#8216;_&#8217;`<br \/>\nif [ &#8220;$f&#8221; != &#8220;$FN&#8221; ];then<br \/>\necho &#8220;&#8212; $f&#8221;<br \/>\nmv &#8220;$f&#8221; $FN<br \/>\nfi<br \/>\ndone<br \/>\necho &#8220;done.&#8221;<br \/>\n197\/433<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Needed to rename all directories and files in a deep directory structure to remove spaces and ugly characters in their names, in order to build a playlist, take a look at this recursive bash shell: #!\/usr\/bin\/bash DIR=\/200gb\/MP3 FTYPE=mp3 renamedir () { cd find . -type d -maxdepth 1 -name &#8220;??*&#8221; | while read d; do [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-419","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=419"}],"version-history":[{"count":0,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/419\/revisions"}],"wp:attachment":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=419"},{"taxonomy":"post_tag","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}