Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Possible Duplicate:
How to clean up file extensions?

I'm using CentOS. There are >10M images in one of my folders, which are furthur grouped into subdirectories.

The issue is that some of my images are named as abc.jpg and others are named as xyz.JPG. So, when i try to access xyz.jpg, it says "File not found" as the extension is case-sensitive.

Is there any way to rename all JPG to jpg, or a httpd config which works around this issue.

share|improve this question

marked as duplicate by Gilles, jasonwryan, Renan, Ulrich Dangel, warl0ck Sep 7 '12 at 5:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

2 Answers 2

up vote 4 down vote accepted

Try this (this will rename all .JPG files to .jpg recursively, in all the subdirectories of the directory where you run this):

find . -name '*.JPG' -exec sh -c 'mv "$0" "${0%.JPG}.jpg"' {} \;

The find searches for all files named *.JPG in the current directory and its subdirectories, passes the list to the mv command which renames them

share|improve this answer
    
more answers here –  Curious Aug 28 '12 at 9:06
    
Thanks a lot for this and link as well! –  Pushpesh Aug 28 '12 at 9:14
add comment

As always with this kind of questions and answers, a few words of caution:

find . -name '*.JPG' -exec sh -c 'mv "$0" "${0%.JPG}.jpg"' {} \;

While it will work OK for most people in most cases, it's dangerous to advertise it publicly as it got a few issues that may turn to security issues in some contexts.

That renames both files and directories. If renaming directories, it will fail to rename files within (use the -depth option)

It will potentially lose files (foo.JPG renamed to foo.jpg while there already was a foo.jpg), or potentially put files where you don't want to (consider for instance a directory where there's a file called foo.JPG and one called foo.jpg that is actually a symlink to /etc/apache2/conf.d. It will potentially break symlinks. There's a race condition that can allow an attacker trick you into renaming any file.

Many of those issues can be avoided by using a tool dedicated for that task (batch renaming of files) instead of trying to reinvent the wheel. mmv and zsh's zmv come to mind.

share|improve this answer
    
Thanks a lot for providing the info. Very helpful. –  Pushpesh Aug 28 '12 at 12:42
add comment

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