-   Linux - General (
-   -   how to change file names to uppercase in a directory (

konramesh 01-30-2006 01:23 AM

how to change file names to uppercase in a directory
All my files are having names in lower case. I wanted to change these names to upper case. I am using red hat linux version 8. How can i change all the file names to upper case in a directory?

pljvaldez 01-30-2006 02:47 AM

Put this script named "ucf" in /usr/local/bin and, as root, type "chmod a+x ucf".


# uppercase any filenames with lowercase chars
for file in $*
 if [ -f $file ]
  ucfile=`echo $file | tr [:lower:] [:upper:]`
  if [ $file != $ucfile ]
    mv -i $file $ucfile

Then you can change all lowercase filenames in the current directory to uppercase by typing "ucf *"

phidor 06-16-2009 02:04 AM

UPPERCASE to lowercase
Can I please ask how this useful script could be modified to change not only the files of a specific directory but also the files found in its subdirectories? If you could do this I would be very grateful.

Thank you. Phidor

ghostdog74 06-16-2009 02:32 AM

if you have Python and don't mind using an already made script, you can try my script called File Renamer(see my sig)
eg usage

# ls -ltR
-rw-r--r-- 1 root root    0 Jun 16 14:29 file1.Doc
-rw-r--r-- 1 root root    0 Jun 16 14:29 testFile.TXT
drwxr-xr-x 2 root root 4096 Jun 16 14:28 test

-rw-r--r-- 1 root root 0 Jun 16 14:28 FILE.PDF
-rw-r--r-- 1 root root 0 Jun 16 14:28 File.TIff
-rw-r--r-- 1 root root 0 Jun 16 14:28 file.txt

# -d 2 -p ".*" -e "a-z" -l "*"
==>>>>  [ /home/test/testFile.TXT ]==>[ /home/test/images/testfile.txt ]
==>>>>  [ /home/test/images/file1.Doc ]==>[ /home/test/images/file1.doc ]
==>>>>  [ /home/test/images/test/FILE.PDF ]==>[ /home/test/images/test/file.pdf ]
==>>>>  [ /home/test/images/test/File.TIff ]==>[ /home/test/images/test/file.tiff ]

-d option means depth level (set to 2 levels deep, so change as appropriate). remove -l option to commit changes

if you don't have Python, then just use normal GNU find

find /home/test/ -type f -name "*[A-Z]*" -printf "%h:%f\n" | awk 'BEGIN{q="\047";FS=":"}
 newpath = $1"/"tolower($2)
 cmd = "mv "q $1"/"$2 q" "q newpath q

phidor 06-16-2009 07:13 AM

Great one! Tried the latter (ie without Python) and it ran like clockwork - first pop. Thanks so much. It was an academic exercise more than a practical necessity - I wanted to see if it could be done. It can! Thank you for your help. I'll now sit down and nut out the code!

Thanks again for such a prompt response!


All times are GMT -5. The time now is 03:34 AM.