Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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 need to change the postfixes of all files (all the same .JPEG) to .jpeg (Capital vs. lower case).
Is there a quick way of doing so?

share|improve this question
up vote 14 down vote accepted

Use the Perl program rename which is installed by default:

rename 's/\.JPEG$/.jpeg/' *.JPEG

The first argument is a Perl regular expression matching filenames ending with .JPEG and replaces it with .jpeg.

The second argument selects the files that should be matched, in your case every file in the current directory ending on .JPEG. You could specify a different location of course:

rename 's/\.JPEG$/.jpeg/' ~/Pictures/*.JPEG

Other answers I've seen:

  • rename s/.JPEG$/.jpeg/ * - this will also rename files like StupidJPEG to Stupi.jpeg because the dot is matches any character. .JPEG$ is a regular expression
  • rename 's/\.JPEG$/\.jpeg/' * - works, but it's less efficient because it passes all files in the current directory to rename.
  • rename -n 's/.JPEG$/.jpeg/' *.JPEG - the -n option would show the files being renamed, without actually renaming them ("dry run"). Because *.JPEG matches files postfixed with .JPEG only, the dot-matches-all issue is non-existent here.
share|improve this answer
The second dot does not need to be escaped because it's not part of the matching expression. In a regular expression, . matches any character (with a few exceptions), therefore the dot needs to be escaped in the regular expression \.JPEG$. – Lekensteyn Jun 11 '11 at 20:56
This also works: for i in *.JPEG; do mv $i $(basename $i .JPEG).jpeg; done – crazy2be Jun 11 '11 at 23:43
@crazy2be: Make an answer of it. It's useful in case rename is not available. Also, $(basename $i .JPEG) can be replaced with ${i%%.JPEG} (bash extension) – Lekensteyn Jun 12 '11 at 8:36

There is a tool for this:

sudo apt-get install renameutils or click renameutils

(if not already installed)

where you can do (from command line):

rename s/\.JPEG$/\.jpeg/ *.JPEG

share|improve this answer

Found it a second after posting:

rename 's/\.JPEG$/.jpeg/' *
share|improve this answer
A small optimization, but for a large amount of files, my answer (and tgm's answer) are preferred because it sends less files to rename for parsing. * matches everything in a directory where *.JPEG would really match just the files postfixed with .JPEG. – Lekensteyn Jun 11 '11 at 21:06

Although this is possibly not the best solution for this particular usage case,

for i in *.JPEG; do mv "$i" "$(basename "$i" .JPEG).jpeg"; done

also works. We can do some trickyness with bash in order to slightly increase efficiency (avoiding in invocation of an additional sub-process in the inner loop), ending up with:

for i in *.JPEG; do mv "$i" "${i%%.JPEG}.jpeg"; done

This solution is most useful if you want to do something else in additon to renaming the files, such as logging what names were changed, or even just doing a dry run to ensure that it does what you want.

share|improve this answer
I recommend putting the variables between double quotes, it's not uncommon for images to have spaces in their names. – Lekensteyn Jun 13 '11 at 8:53
Done! I forgot about that, it worked in my test (files named 1-1000.JPEG sequentially) :P. – crazy2be Jun 14 '11 at 4:39

Use the rename command. It's different than move and often is causes confusion because it was specifically created with picture renaming in mind.

Something like this command should work (for all files that end in .JPEG, change .JPEG to .jpeg)

rename -n 's/.JPEG$/.jpeg/' *.JPEG

share|improve this answer

Doing things in parallel is getting more and more important, hence I recommend:

parallel mv {} {.}.jpg ::: *.JPG

This utility is not installed by default though.

share|improve this answer
Nice to know about this, but I really need something quick and Dirty, and do not really care for performance/efficiency – Itay Moav -Malimovka Jun 12 '11 at 11:33

If you are looking for a nice GUI solution and don't want to muck about with complicated command line arguments, there is a great Nautilus script available to rename files. It has a simple interface and many options.

Available here:

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.