{"id":1162,"date":"2023-11-16T00:00:00","date_gmt":"2023-11-16T05:00:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=1162"},"modified":"2024-02-05T10:36:46","modified_gmt":"2024-02-05T15:36:46","slug":"bash-renaming-multiple-files","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/bash-renaming-multiple-files\/","title":{"rendered":"bash: Renaming multiple files"},"content":{"rendered":"\n<p>To rename multiple files using the command line, you can use the rename command or a shell script. Its syntax is as follows.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ rename regular_expression files<\/code><\/pre>\n\n\n\n<p>As you can see, the catch is that you need to know regular expressions. But for simpler tasks, regular expressions are really easy. For example,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ rename *.htm *.html<\/code><\/pre>\n\n\n\n<p>This changes the extension of all files from .htm to .html.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ rename \u201cs\/ *\/\/g\u201d *.jpg<\/code><\/pre>\n\n\n\n<p>This code removes spaces from filenames. Rename functions can be used for more powerful renaming features but the limitation is what you can do with a regular expression. For more powerful features, you need to write a shell script. The following shell script renames all photos in a folder to rockies-100.jpg, rockies-101.jpg, \u2026<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">i=100<br>for j in&nbsp;<em>.jpg;<br>&nbsp; &nbsp;do mv \u201c$j\u201d \u201crockies-$i.jpg\u201d ;(( i++ ));<br>done<\/em><\/pre>\n\n\n\n<p>A note about shell scripts. Do not add additional space i = 1 is not the same as i=1<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To rename multiple files using the command line, you can use the rename command or a shell script. Its syntax is as follows. As you can see, the catch is that you need to know regular expressions. But for simpler tasks, regular expressions are really easy. For example, This changes the extension of all files [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1448,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101,34],"tags":[94,383],"class_list":["post-1162","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash","category-linux","tag-bash","tag-command-line-tips"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=1162"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1162\/revisions"}],"predecessor-version":[{"id":1163,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1162\/revisions\/1163"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media\/1448"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=1162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=1162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=1162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}