{"id":1152,"date":"2023-11-11T00:00:00","date_gmt":"2023-11-11T05:00:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=1152"},"modified":"2024-02-05T10:37:35","modified_gmt":"2024-02-05T15:37:35","slug":"bash-how-to-change-file-extensions","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/bash-how-to-change-file-extensions\/","title":{"rendered":"bash: How to change file extensions"},"content":{"rendered":"\n<p>This post shows how to change file extensions using bash.<\/p>\n\n\n\n<p><strong>To change file extensions, we simple need to loop through file in a directory and use the \u201cmv\u201d command to rename each file.<\/strong><\/p>\n\n\n\n<p>The following code requests directory address from the user and then renames all \u201c<strong>.log<\/strong>\u201d files to \u201c<strong>.txt<\/strong>\u201c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash \necho \"Specify a directory: \" \nread folder \ncd $folder \nfor i in *.log     \n    do     \n    mv \"$i\" `basename $i log`txt \ndone<\/code><\/pre>\n\n\n\n<p>Line 2 ask print the message \u201cSpecify a directory\u201d.<br>Line 3 reads response from the user and stored it in the variable \u201cfolder\u201d.<br>Line 4 take the control to that directory<br>Line 4-8 is the for loop that loop through all files with the extension \u201c.log\u201d.<br>Line 6 renames .log file to .txt<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post shows how to change file extensions using bash. To change file extensions, we simple need to loop through file in a directory and use the \u201cmv\u201d command to rename each file. The following code requests directory address from the user and then renames all \u201c.log\u201d files to \u201c.txt\u201c Line 2 ask print the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1214,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101,34],"tags":[94,383,209],"class_list":["post-1152","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash","category-linux","tag-bash","tag-command-line-tips","tag-file-management"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1152","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=1152"}],"version-history":[{"count":2,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1152\/revisions"}],"predecessor-version":[{"id":1215,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1152\/revisions\/1215"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media\/1214"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=1152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=1152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=1152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}