Skip to content

How to Change Filenames to tOggLe Case in Linux

Many time you may need to change the file or folder name case, for example lower to upper, upper to lower or toggle the case. I am giving you to the best solution to change the folder name case. We need to create a command for easy access. First of all create a script in “/usr/local/bin” folder and give it the execute permission, so any user can access this function as a command. I named this script tcf (toggle case file) but you can user your name that you can easily remember and identify. Note: You need super user privilege.

Create a script and put this script named “tcf” in /usr/local/bin and type “chmod a+x tcf”.

sudo vi /user/local/bin/tcf
#!/bin/sh
# uppercase any filenames with lowercase chars
for file in $*
do
if [ -f $file ]
then
tcfile=`echo $file | tr '[:lower:][:upper:]' '[:upper:][:lower:]'`
if [ $file != $tcfile ]
then
mv -i $file $tcfile
fi
fi
done
sudo chmod a+x /user/local/bin/tcf

Uses:

$ tcf
OR
$ tcf [ ...]

Chage all file in a folder:

$ tcf `ls *`