Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have about 2k of file that are currently in lower case like:


I am searching for a fast way to rename them to upper case so they would be like;


If I use from my shell;

for i in *; do mv $i `echo $i | tr [:lower:] [:upper:]`; done

I can get all file and the file extensions to upper case.

But the extension should remain in lowercase, so my approach does not work.

Any programming language is welcome.

share|improve this question

migrated from Apr 11 '10 at 23:26

This question came from our site for professional and enthusiast programmers.

up vote 2 down vote accepted

You can always use the free Bulk Rename utility.

share|improve this answer
Thank you @Oded that is what I need. – Adnan Apr 11 '10 at 13:59
That seems to be for Windows. – Dennis Williamson Apr 11 '10 at 23:45
I don't understand, judging from the tags of the question, the OP is asking for a linux shell command, and you reply proposing a windows GUI application? – mrucci Apr 15 '10 at 12:41

In any shell:

for i in *.cfr 
    mv "$i" "$(echo ${i%.cfr} | tr [:lower:] [:upper:]).cfr"; 

It is based on your proposed solution but uses the parameter expansion ${parameter%word} to strip the extension from the filename.

share|improve this answer
You should probably quote the second expansion of i to preserve IFS characters other than SPC (e.g. TAB and LF). Also, you might quote the character classes for shells that are configured to delete or produce an error for non-matching globs. – Chris Johnsen May 18 '10 at 5:07

if you have bash 4.0


for file in file_*cfr
  echo mv "$file" "$newfile"

or you can use just awk

awk '
  cmd="mv \047"FILENAME"\047 \047"newfile"\047"
  # system(cmd) #uncomment to use
' file_*cfr
share|improve this answer
you would need perhaps | bash at the very end – Vlad Apr 11 '10 at 14:29

You may already have a Perl script on your system called rename or prename.

rename 's/([^.]*)/\U$1/' *.cfr

Or here's a version of Vlad's script that eliminates the need for grep and sed (it will work in Bash versions earlier than version 4 since it uses tr instead of the ^^ operator):


for f in *.cfr
    if [[ "$f" == "${f//.}" ]]; then continue; fi
    newfullname="$(<<< "$name" tr [:lower:] [:upper:])$ext"
    [[ "$f" == "$newfullname" ]] || mv "$f" "$newfullname"
share|improve this answer

for f in *
    <<< $f grep -q "\." || continue
    name=$(<<<$f sed 's/\.[^\.]*$//')
    ext=$(<<< $f sed 's/^.*\(\.[^\.]*\)$/\1/')
    newfullname=$(<<< $name tr [:lower:] [:upper:])$ext
    [ "$f" == "$newfullname" ] || mv "$f" "$newfullname"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.