{"id":13256,"date":"2019-04-01T09:55:54","date_gmt":"2019-04-01T09:55:54","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13256"},"modified":"2019-04-01T09:55:54","modified_gmt":"2019-04-01T09:55:54","slug":"rename-all-files-and-directory-names-to-lowercase-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/rename-all-files-and-directory-names-to-lowercase-in-linux\/","title":{"rendered":"Rename All Files and Directory Names to Lowercase in Linux"},"content":{"rendered":"<p>This guide will show you how to rename all files and directories names to lowercase in Linux.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/find-top-large-directories-and-files-sizes-in-linux\/\" target=\"_blank\" rel=\"noopener\">How to Find Out Top Directories and Files (Disk Space) in Linux<\/a><\/p>\n<p>There are several ways to achieve this, but we\u2019ll explain two of the most efficient and reliable methods. For the purpose of this guide, we have used a directory named\u00a0<code>Files<\/code>\u00a0which has the following structure:<\/p>\n<pre># find Files -depth\r\n<\/pre>\n<div id=\"attachment_27156\" class=\"wp-caption aligncenter\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27156\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/09\/List-Directory-Structure.png\" alt=\"List Directory Structure\" width=\"562\" height=\"230\" aria-describedby=\"caption-attachment-27156\" data-lazy-loaded=\"true\" \/><\/p>\n<p id=\"caption-attachment-27156\" class=\"wp-caption-text\">List Directory Structure<\/p>\n<\/div>\n<h3>1. Using find, xargs and rename Commands Together<\/h3>\n<p><a href=\"https:\/\/www.tecmint.com\/rename-multiple-files-in-linux\/\" target=\"_blank\" rel=\"noopener\">rename<\/a>\u00a0is a simple command line utility for renaming several files at once in Linux. You can use it together with\u00a0<a href=\"https:\/\/www.tecmint.com\/35-practical-examples-of-linux-find-command\/\" target=\"_blank\" rel=\"noopener\">find utility<\/a>\u00a0to rename all files or subdirectories in a particular directory to lowercase as follows:<\/p>\n<pre>$ find <strong>Files<\/strong> -depth | xargs -n 1 rename -v 's\/(.*)\\\/([^\\\/]*)\/$1\\\/\\L$2\/' {} \\;\r\n<\/pre>\n<p>Explanation of options used in the above command.<\/p>\n<ul>\n<li><code>-depth<\/code>\u00a0\u2013 lists each directory\u2019s contents before the directory itself.<\/li>\n<li><code>-n 1<\/code>\u00a0\u2013 instructs\u00a0<strong>xargs<\/strong>\u00a0to use at most one argument per command line from\u00a0<strong>find<\/strong>\u00a0output.<\/li>\n<\/ul>\n<p>Sample output after renaming files and subdirectories to lowercase in\u00a0<code>Files<\/code>\u00a0directory.<\/p>\n<div id=\"attachment_27157\" class=\"wp-caption aligncenter\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27157\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/09\/Rename-Files-and-Directory-Names-to-Lowercase.png\" sizes=\"auto, (max-width: 992px) 100vw, 992px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/09\/Rename-Files-and-Directory-Names-to-Lowercase.png 992w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/09\/Rename-Files-and-Directory-Names-to-Lowercase-768x355.png 768w\" alt=\"Rename Files and Directory Names to Lowercase\" width=\"992\" height=\"458\" aria-describedby=\"caption-attachment-27157\" data-lazy-loaded=\"true\" \/><\/p>\n<p id=\"caption-attachment-27157\" class=\"wp-caption-text\">Rename Files and Directory Names to Lowercase<\/p>\n<\/div>\n<p>Another alternative way using the\u00a0<a href=\"https:\/\/www.tecmint.com\/35-practical-examples-of-linux-find-command\/\" target=\"_blank\" rel=\"noopener\">find<\/a>\u00a0and\u00a0<a href=\"https:\/\/www.tecmint.com\/progress-monitor-check-progress-of-linux-commands\/\" target=\"_blank\" rel=\"noopener\">mv commands<\/a>\u00a0in a script as explained below.<\/p>\n<h3>2. Using find and mv Commands in Shell Script<\/h3>\n<p>First create your script (you can name it anything you prefer):<\/p>\n<pre>$ cd ~\/bin\r\n$ vi rename-files.sh\r\n<\/pre>\n<p>Then add the code below in it.<\/p>\n<pre>#!\/bin\/bash\r\n#print usage \r\nif [ -z $1 ];then\r\n        echo \"Usage :$(basename $0) parent-directory\"\r\n        exit 1\r\nfi\r\n\r\n#process all subdirectories and files in parent directory\r\nall=\"$(find $1 -depth)\"\r\n\r\n\r\n\r\nfor name in ${all}; do\r\n        #set new name in lower case for files and directories\r\n        new_name=\"$(dirname \"${name}\")\/$(basename \"${name}\" | tr '[A-Z]' '[a-z]')\"\r\n\r\n        #check if new name already exists\r\n        if [ \"${name}\" != \"${new_name}\" ]; then\r\n                [ ! -e \"${new_name}\" ] &amp;&amp; mv -T \"${name}\" \"${new_name}\"; echo \"${name} was renamed to ${new_name}\" || echo \"${name} wasn't renamed!\"\r\n        fi\r\ndone\r\n\r\necho\r\necho\r\n#list directories and file new names in lowercase\r\necho \"Directories and files with new names in lowercase letters\"\r\nfind $(echo $1 | tr 'A-Z' 'a-z') -depth\r\n\r\nexit 0\r\n<\/pre>\n<p>Save and close the file, then make the script executable and run it:<\/p>\n<pre>$ chmod +x rename-files.sh\r\n$ rename-files.sh <strong>Files<\/strong>     #Specify Directory Name\r\n<\/pre>\n<div id=\"attachment_27158\" class=\"wp-caption aligncenter\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27158\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/09\/Lowercase-File-and-Directories-using-Script.png\" alt=\"Lowercase File Names Using Script\" width=\"762\" height=\"456\" aria-describedby=\"caption-attachment-27158\" data-lazy-loaded=\"true\" \/><\/p>\n<p id=\"caption-attachment-27158\" class=\"wp-caption-text\">Lowercase File Names Using Script<\/p>\n<\/div>\n<p>You may also like to read these following related articles.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/explanation-of-everything-is-a-file-and-types-of-files-in-linux\/\" target=\"_blank\" rel=\"noopener\">Explanation of \u201cEverything is a File\u201d and Types of Files in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/fswatch-monitors-files-and-directory-changes-modifications-in-linux\/\" target=\"_blank\" rel=\"noopener\">fswatch \u2013 Monitors Files and Directory Changes or Modifications in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/fasd-quick-access-to-linux-files-and-directories\/\" target=\"_blank\" rel=\"noopener\">Fasd \u2013 A Commandline Tool That Offers Quick Access to Files and Directories<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/fslint-find-and-remove-duplicate-unwanted-files-in-linux\/\" target=\"_blank\" rel=\"noopener\">FSlint \u2013 How to Find and Remove Duplicate Files in Linux<\/a><\/li>\n<\/ol>\n<p>In this guide, we expalined you how to rename all files and directories to lowercase in Linux. If get any errors, please hit us up via the feedback form below. You can as well offer us any other methods of doing the same.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/rename-all-files-and-directory-names-to-lowercase-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide will show you how to rename all files and directories names to lowercase in Linux. Read Also:\u00a0How to Find Out Top Directories and Files (Disk Space) in Linux There are several ways to achieve this, but we\u2019ll explain two of the most efficient and reliable methods. For the purpose of this guide, we &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/rename-all-files-and-directory-names-to-lowercase-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Rename All Files and Directory Names to Lowercase in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13256","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13256"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13256\/revisions"}],"predecessor-version":[{"id":13257,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13256\/revisions\/13257"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}