Convert Filenames to Lowercase through Ubuntu Command Line

While working with Linux, you might come across some utilities and apps that only work with file names in lowercase. We do not usually save files in this format and might have to look for a workaround that recursively converts all filenames in a folder to lowercase. In this article, we will show you two ways to convert all files and folder names in a given path to lowercase, simply through the command line.

We have run the commands and procedures mentioned in this article on a Ubuntu 18.04 LTS system.

Here is how you can list the contents of your folder using the find command:

$ find [directory_name] -depth

My Downloads folder, which I will be using as a sample for this article, has all files starting from uppercase letters and also contains a few in between the names.

$ find Downloads -depth

List files with the find command

Method 1: Using the rename command

In this method, we will be making use of the Ubuntu find, Xargs and rename commands in order to recursively rename all files/folders in a given directory.

Open your Ubuntu command line, the Terminal, either through the Application Launcher search or the Ctrl+Alt+T shortcut.

Here is the syntax of the command you will be using:

$ find [directory_name] -depth | xargs -n 1 rename -v ‘s/(.*)\/([^\/]*)/$1\/\L$2/’ {} \;

If you do not have the rename command installed on your system, you might get an error when you run the above command. You can install rename to your Ubuntu through the following apt-get command:

$ sudo apt-get install rename

I will be using the following command in order to convert filenames to lowercase in my Downloads directory:

$ find Downloads -depth | xargs -n 1 rename -v 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;

Change file names to lowercase on Linux

When I listed the contents of the directory again, I was able to see all file names converted to lowercase as follows:

Filename list

Method 2: Using a script to rename the files

In this method, we will make use of a bash script that uses the find and mv commands in order to recursively rename file and folder names of a directory, including the directory name itself.

Open the Terminal application and move to the bin folder as follow:

$ cd ~bin

Now, open a new script file in one of your favorite text editors. We will use the nano editor in order to open an empty script file by the name of

$ sudo nano

In that empty file, add the following script.

#print usage
if [ -z $1 ];then
echo "Usage :$(basename $0) parent-directory"
exit 1

#process all subdirectories and files in parent directory
all="$(find $1 -depth)"

for name in ${all}; do
#set new name in lower case for files and directories
new_name="$(dirname "${name}")/$(basename "${name}" | tr '[A-Z]' '[a-z]')"
#check if new name already exists
if [ "${name}" != "${new_name}" ]; then
[ ! -e "${new_name}" ] && mv -T "${name}" "${new_name}"; echo "${name} was renamed to ${new_name}" || echo "${name} wasn't renamed!"

exit 0

Tip: Instead of typing the whole script into you bash file, you can copy it from here and paste in the Terminal by using the Ctrl+Shift+V, or by using the Paste option from the right-click menu.

This is how your file will look like:

File lowercase rename script

Now, exit the file through the Ctrl+X shortcut and save the file on the “Save modified buffer?” prompt by typing Y and then hitting enter.

In order to make this file an executable script, run the following command in your Terminal:

$ sudo chmod +x

Now you are ready to use the script on any of your folders.

When I run the script on my Downloads folder, I see all the files and subfolders names converted to lowercase as follows:

Run script to turn filenames to lower case

So, these were the two ways through which you can rename the filenames to all lowercase letters so that the application you are using does not fail to recognize any uppercase files names.