LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 01-30-2006, 01:23 AM   #1
konramesh
LQ Newbie
 
Registered: Jan 2006
Posts: 3

Rep: Reputation: 0
Question 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?
 
Old 01-30-2006, 02:47 AM   #2
pljvaldez
Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092

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

Code:
#!/bin/sh
# uppercase any filenames with lowercase chars
for file in $*
 do
 if [ -f $file ]
 then
   ucfile=`echo $file | tr [:lower:] [:upper:]`
   if [ $file != $ucfile ]
   then
     mv -i $file $ucfile
   fi     
 fi
done
Then you can change all lowercase filenames in the current directory to uppercase by typing "ucf *"
 
1 members found this post helpful.
Old 06-16-2009, 02:04 AM   #3
phidor
Member
 
Registered: Apr 2005
Location: Timaru, New Zealand
Distribution: Linux Mint 9
Posts: 104

Rep: Reputation: 15
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
 
Old 06-16-2009, 02:32 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
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
Code:
# 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

./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

# filerenamer.py -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
Code:
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 
 system(cmd)
}
'
 
Old 06-16-2009, 07:13 AM   #5
phidor
Member
 
Registered: Apr 2005
Location: Timaru, New Zealand
Distribution: Linux Mint 9
Posts: 104

Rep: Reputation: 15
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!

Phidor.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting file names in a directory using C on linux. rajsun Programming 4 06-10-2005 01:47 AM
Script to change names of files in a directory geomonap Linux - General 2 12-03-2004 04:04 PM
monitoring directory to get the modified file names appas Programming 1 09-06-2004 05:56 AM
change file names to lowercase. david_wliu Linux - General 4 03-10-2003 02:17 PM
change file names to lowercase. david_wliu Programming 2 03-10-2003 01:59 PM


All times are GMT -5. The time now is 10:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration