{"id":18820,"date":"2022-10-04T15:56:25","date_gmt":"2022-10-04T15:56:25","guid":{"rendered":"https:\/\/linuxways.net\/?p=18820"},"modified":"2022-11-04T02:50:54","modified_gmt":"2022-11-04T02:50:54","slug":"remove-file-extension-filename-bash","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/bash-programming\/remove-file-extension-filename-bash\/","title":{"rendered":"How to Remove the File Extension From the Filename in Bash?"},"content":{"rendered":"<p>\u201cWhile doing bash programming, you might come across a situation in which you are dealing with files; however, <a id=\"post-18820-_Hlk114906568\"><\/a>you are only interested in their names without their extensions. In such situations, you need to have some methods through which you can remove the file extension from a filename. Therefore, we have designed this tutorial to show you how you can do this in Linux Mint 21.\u201d<\/p>\n<h2><strong>Methods of Removing the File Extension From the Filename in Bash<\/strong><\/h2>\n<p>Removing the extension of a file from its name is very easy in Bash, and you can follow either of the two methods explained below to do this:<\/p>\n<h3><strong>Method # 1: Specifying the Extension to be Removed With the Basename Command<\/strong><\/h3>\n<p>To use this method, you simply need to execute the following command:<\/p>\n<pre>\r\n$ basename \/home\/system\/result.txt .txt\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"532\" height=\"25\" class=\"wp-image-18829\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18820-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18820-1.png 532w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18820-1-300x14.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18820-1-501x25.png 501w\" sizes=\"auto, (max-width: 532px) 100vw, 532px\" \/><\/strong><\/p>\n<p>Here, you need to specify the complete path of the file (whose extension you wish to remove), including its filename and extension, followed by the \u201c.txt\u201d extension again. This will tell the basename command to remove this extension from the output. If you have a file other than the text file, then you can specify its particular extension instead of \u201c.txt,\u201d and it will be removed in the very same manner.<\/p>\n<p>The name of our file with its extension removed is shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"542\" height=\"59\" class=\"wp-image-18831\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18820-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18820-2.png 542w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18820-2-300x33.png 300w\" sizes=\"auto, (max-width: 542px) 100vw, 542px\" \/><\/p>\n<h3><strong>Method # 2: Specifying the Extension to be Removed Along With the \u201c-s\u201d Flag With the Basename Command<\/strong><\/h3>\n<p>To adopt this method, you need to run the following command:<\/p>\n<pre>\r\n$ basename \u2013s .txt \/home\/system\/result.txt\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"553\" height=\"25\" class=\"wp-image-18833\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18820-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18820-3.png 553w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18820-3-300x14.png 300w\" sizes=\"auto, (max-width: 553px) 100vw, 553px\" \/><\/strong><\/p>\n<p>Again, you can replace the \u201c.txt\u201d extension after the \u201c-s\u201d flag in this command with the particular extension of your file that you wish to remove.<\/p>\n<p>The output of this command is given in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"567\" height=\"58\" class=\"wp-image-18835\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18820-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18820-4.png 567w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18820-4-300x31.png 300w\" sizes=\"auto, (max-width: 567px) 100vw, 567px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>In this article, we have shared two different ways of removing the file extension from the filename in Linux Mint 21. Now, it is totally a matter of your choice which method you make use of to achieve this goal.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>While doing bash programming, you are only interested in their names without their extensions. This article explains two ways of removing the file extension.<\/p>","protected":false},"author":3,"featured_media":18879,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1050],"tags":[],"class_list":["post-18820","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-programming"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18820","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=18820"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18820\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/18879"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=18820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=18820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=18820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}