Convert File Names to Lowercase

In Linux, file names are case-sensitive, so you might face situations where you want to change file names to lowercase. In general, it’s easier to work with files on the Linux command line that are entirely lowercase. In this tutorial, you will learn how to change file names to lowercase with Linux commands.

mv Command

You can use the mv command not only for moving directories and files but also for altering file names.

Example 1. The for loop below will change file names to lowercase for all files in the current directory by using mv and tr.

$ for f in * ; do mv $f $(echo $f | tr A-Z a-z); done

Example 2. The awk command also has a built in tolower function that we can use.

$ for f in * ; do mv $f `echo $f | awk '{print tolower($0)}'`; done

rename Command

Installing rename:

$ sudo apt install rename # Ubuntu, Debian
$ sudo dnf install prename # Fedora, CentOS, AlmaLinux, Rocky
$ sudo pacman -S perl-rename # Arch Linux, Manjaro

Example 1. Use the rename command to change an individual file to lowercase.

$ rename 'y/A-Z/a-z/' file_name

Example 2. To make all file names lowercase, we can use a wildcard. Keep in mind that directories will also change to lowercase.

$ rename 'y/A-Z/a-z/' *

mmv Command

Installing mmv:

$ sudo apt install mmv # Ubuntu, Debian
$ sudo dnf install mmv # Fedora, CentOS, AlmaLinux, Rocky

mmv has the shortest command syntax to change all file names to lowercase:

$ mmv '*' '#l1'
Check out Renaming Multiple Files at Once for more examples.

Leave a Comment

Your email address will not be published. Required fields are marked *