{"id":224,"date":"2016-05-31T07:28:11","date_gmt":"2016-05-31T07:28:11","guid":{"rendered":"http:\/\/alain.fi\/?p=224"},"modified":"2019-07-30T03:59:38","modified_gmt":"2019-07-30T03:59:38","slug":"reorder-files-by-renaming","status":"publish","type":"post","link":"https:\/\/alain.fi\/?p=224","title":{"rendered":"reorder files by renaming"},"content":{"rendered":"<p>To rename files the way this can list them:\u00a0ls -lv<\/p>\n<p>This is needed when for example you need to handle bunch of images named like:<br \/>\n1 front.jpg -&gt; 0001.jpg<br \/>\n02.jpg-&gt; 0002.jpg<br \/>\n3.jpg-&gt; 0003.jpg<br \/>\n10.jpg-&gt; 0004.jpg<\/p>\n<p>Found somewhere in the net, working great. Just test with echo and remove echo when ready. Need to also fix the files with space in name.<\/p>\n<pre>#!\/bin\/bash\r\ndef=0000\r\nfor f in $(ls -v *.jpg);do\r\n ((cnt++))\r\n if [[ ! -e \"${def:${#cnt}:${#def}}${cnt}.jpg\" ]];then\r\n echo mv \"${f}\" \"${def:${#cnt}:${#def}}${cnt}.jpg\" #remove preceding echo if everything is fine\r\n fi\r\ndone<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To rename files the way this can list them:\u00a0ls -lv This is needed when for example you need to handle bunch of images named like: 1 front.jpg -&gt; 0001.jpg 02.jpg-&gt; 0002.jpg 3.jpg-&gt; 0003.jpg 10.jpg-&gt; 0004.jpg Found somewhere in the net, &hellip; <a href=\"https:\/\/alain.fi\/?p=224\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-224","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/alain.fi\/index.php?rest_route=\/wp\/v2\/posts\/224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alain.fi\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alain.fi\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alain.fi\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alain.fi\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=224"}],"version-history":[{"count":2,"href":"https:\/\/alain.fi\/index.php?rest_route=\/wp\/v2\/posts\/224\/revisions"}],"predecessor-version":[{"id":226,"href":"https:\/\/alain.fi\/index.php?rest_route=\/wp\/v2\/posts\/224\/revisions\/226"}],"wp:attachment":[{"href":"https:\/\/alain.fi\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alain.fi\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alain.fi\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}