Thursday, March 13, 2008

HowTo: Convert First Letter of Dir Folder to Uppercase

Well, if we can convert the first letter of each lines from a text file, we can use the same approach to convert the first letter of a directory or folder name to its uppercase as well, simply add the linux mv command.

If you have hundreds of directory name in one location that starts their directory folder name with small letters, and you with to rename directory where its first letter is in uppercase form, read on.

With reference to recent post, here is a short entry where you can convert all first letter of all directory folder names into its uppercase form.

How To Convert First Letter of Directory Folder To Its Uppercase Form

Taking a longer approach would be like creating an executable bash shell script like so

# cat rename-folder.sh
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/bash
ls -la | grep dr | grep -v "\." | awk '{print $8}' | while read -r FOLDER
do
newfoldername=`echo $FOLDER | sed -e 's/\(.\)\(.*\)/\u\1\2/'`
echo OLD Name: [$FOLDER] TO NEW Name: [$newfoldername]
# You know what to do from this line -
# Rename the old to new
# using mv linux command
done
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Enjoy the weekend.

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy