Rename all file names from uppercase to lowercase characters

As a Linux user, you’re likely already familiar with using the mv command to rename a file on a Linux system. The task becomes a little more difficult when you need to rename multiple files at the same time on Linux.

One of the most common batch renaming jobs that are performed is to change all file names to lowercase letters. There are several different ways to do this on Linux. One way is with the native mv utility and a bit of Bash scripting, and the other methods involve the rename and mmv tools, which may or may not already be installed on your Linux distro by default.

In this guide, we’ll go over various command line examples to rename all files from uppercase to lowercase letters on Linux. Some commands will work only for files, some for directories, and some commands work recursively. Take a look at all the different examples below to decide which command(s) to use that would best suit your needs.

In this tutorial you will learn:

  • How to rename all files from uppercase to lowercase using mv, rename, or mmv commands
  • How to install rename and mmv on major Linux distros

Using the mv, rename, and mmv commands to rename files between uppercase and lowercase on Linux

Using the mv, rename, and mmv commands to rename files between uppercase and lowercase on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software mv, rename, mmv
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Rename files from uppercase to lowercase with mv command



Renaming multiple files from uppercase to lowercase with the mv command is easier if you know a little bit of Bash scripting. The rename and mmv utilities make renaming multiple files a lot simpler, and allow us to do some pretty advanced renaming without using complex commands.

The examples below will show how to use all three methods to rename files from uppercase to lowercase. Before getting started, if you choose to use the rename or mmv commands, you’ll want to make sure they are installed on your system by using the appropriate command below.

To install rename or mmv on Ubuntu, Debian, and Linux Mint:

rename:
$ sudo apt install rename

mmv:
$ sudo apt install mmv

To install rename or mmv on CentOS, Fedora, AlmaLinux, and Red Hat:

rename:
$ sudo dnf install prename

mmv:
$ sudo dnf install mmv

To install rename or mmv on Arch Linux and Manjaro:

rename:
$ sudo pacman -S perl-rename

mmv:
$ git clone https://aur.archlinux.org/mmv.git
$ cd mmv/
$ makepkg -si


  1. The following command will rename uppercase files to lowercase characters by using the mv command and other native tools.
    $ for i in $( ls | grep [A-Z] ); do mv -i $i `echo $i | tr 'A-Z' 'a-z'`; done
    

    In case you are using Cyrillic or any other UTF8 characters you can try the following to change any file names to uppercase:

    $ for i in $( ls ); do mv -i $i `echo $i | PERLIO=:utf8 perl -pe '$_=uc'`; done
    
  2. Alternatively, it’s a lot more concise to use the rename command to change all file names to lowercase letters.
    $ rename -f 'y/A-Z/a-z/' *
    
  3. A third option is to use the mmv command to rename all uppercase letters to lowercase. This may be the simplest option yet.
    $ mmv '*' '#l1'
    
  4. You can use the following method to change all file and folder names to lowercase recursively.
    $ find . -depth | xargs -n 1 rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;
    
  5. This command will change file names only from uppercase to lowercase, recursively.
    $ find . -depth -type f | xargs -n 1 rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;
    
  6. You can also change the -type option so the next command can change directory names only from uppercase to lowercase, recursively.
    $ find . -depth -type d | xargs -n 1 rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;
    
  7. You can also do the exact opposite by adapting these commands slightly. For example, this command will change all lowercase file names to uppercase.
    $ for i in $( ls | grep [a-z] ); do mv -i $i `echo $i | tr 'a-z' 'A-Z'`; done
    
  8. The rename utility can also be used to change all lowercase file names to uppercase.
    $ rename -f 'y/a-z/A-Z/' *
    
  9. Once again, with perhaps the simplest option of all, mmv can rename all files from lowercase to uppercase with this command.
    $ mmv '*' '#u1'
    
  10. Here’s how to recursively rename all files and directories from lowercase to uppercase.
    $ find . -depth | xargs -n 1 rename 's/(.*)\/([^\/]*)/$1\/\U$2/' {} \;
    
  11. Here’s how to recursively rename files only from lowercase to uppercase.
    $ find . -depth -type f | xargs -n 1 rename 's/(.*)\/([^\/]*)/$1\/\U$2/' {} \;
    
  12. Lastly, here’s an example for recursively renaming directories only from lowercase to uppercase.
    $ find . -depth -type d | xargs -n 1 rename 's/(.*)\/([^\/]*)/$1\/\U$2/' {} \;
    


Closing Thoughts

In this guide, we learned several different methods to rename multiple files from uppercase to lowercase characters on Linux. We also saw how to do the opposite – renaming files from lowercase to uppercase. This can be done on both files and directories. And, as another option, we can rename all files recursively. Bulk renaming can be done through native bash utilities like mv, ls, xargs, and find, or we can install the mmv or rename utility to make our life a little easier. Every method has their strengths and weaknesses, so use whichever one you think will be most convenient for you.



Comments and Discussions
Linux Forum