[Solved] Rename all file names from uppercase to lowercase characters in a directory

Rename all file names from uppercase to lowercase characters in a directory

This can happen with anyone working on a static website or help pages. Microsoft Windows does not care about the case sensitivity but Linux is really concerned about it. I encountered this issue while working on a documentation where all the pages were in upper cases whereas web server was looking for lower cases. Due to this issue, I was getting 404 not found error on lots of pages. I used under given command to rename all files names from uppercase to lowercase characters in a directory. There are multiple commands shared on internet which claims that they can do this task but only this one worked for me.

ls | sed -n 's/.*/mv "&" $(tr "[A-Z]" "[a-z]" <<< "&")/p' | bash

If you are using a cloud Linux distribution from a modified image, you might face a access denied issue. You can solve this issue by giving full rights during the renaming process and once done can revert back. You might also need to issue this command with sudo. Make sure  you have a backup before performing this operation to avoid any inconvenience.

Change permissions

chmod command can be used to reset the permission of all the files in a directory with lots of switches available to apply to get the desired results.

find /path/to/public_html/ -type f -exec chmod 0644 {} +

Use the above command to adjust the permission if you have changed it for all the files.

find /path/to/public_html/ -type d -exec chmod 0755 {} +

Above command can be used to reset the permissions of the directory and sub-directories.

For more information about changing the permissions of files, directories and sub-directories, please follow the under listed URL:

https://askubuntu.com/questions/676822/how-do-i-specify-folders-only-for-chmod

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.