{"id":42,"date":"2011-01-19T19:06:29","date_gmt":"2011-01-19T18:06:29","guid":{"rendered":"http:\/\/trigonakis.com\/blog\/?p=42"},"modified":"2011-02-17T19:38:46","modified_gmt":"2011-02-17T18:38:46","slug":"really-simple-batch-renaming-in-linux","status":"publish","type":"post","link":"http:\/\/trigonakis.com\/blog\/2011\/01\/19\/really-simple-batch-renaming-in-linux\/","title":{"rendered":"Really simple batch renaming in Linux"},"content":{"rendered":"<p>While working on the photos section of trigonakis.com, I wanted to batch rename some photos, so after the renaming their new name would be prefix_<strong>i<\/strong>,<strong> <\/strong>where\u00a0<strong>i<\/strong> is a incremental value. The following (stupidly) simple bash script provides the desired functionality:<\/p>\n<pre lang=\"bash\">#!\/bin\/bash\r\n\r\nINDEX=1\r\n\r\nfor i in *.$1; do\r\n  echo item $INDEX: \"$i\" renamed to $2_$INDEX.$1\r\n  mv \"$i\" $2_$INDEX.$1\r\n  let INDEX=INDEX+1\r\ndone\r\n<\/pre>\n<p>Usage:<\/p>\n<pre lang=\"bash\">\r\n#make the script executable\r\nchmod +x scriptname.sh\r\n#move the folder containing the files to be renamed\r\nmv from_path\/scriptname.sh to_path\/\r\n#run the script\r\n.\/scriptname.sh FILE_EXTENSION NAME_PREFIX\r\n#example:\r\n.\/rnm.sh JPG photo\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>While working on the photos section of trigonakis.com, I wanted to batch rename some photos, so after the renaming their new name would be prefix_i, where\u00a0i is a incremental value. The following (stupidly) simple bash script provides the desired functionality: #!\/bin\/bash INDEX=1 for i in *.$1; do echo item $INDEX: &#8220;$i&#8221; renamed to $2_$INDEX.$1 mv [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[37],"tags":[10,9],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1ouW6-G","_links":{"self":[{"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/posts\/42"}],"collection":[{"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/comments?post=42"}],"version-history":[{"count":11,"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/posts\/42\/revisions"}],"predecessor-version":[{"id":204,"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/posts\/42\/revisions\/204"}],"wp:attachment":[{"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/media?parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/categories?post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/tags?post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}