Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a Media Temple (dv) server which I am setting Magento up on.

I have uploaded a few thousand images to the /media/import directory that the client has provided me with. The problem is, some images are .jpg and others are .JPG.

Is there a way of batch renaming them on the server? I really don't want to have to do it locally and the re-upload them all.

I would ideally make them all lowercase so that they are uniform with the other image naming schemes used by Magento.

Thanks,

Danny

share|improve this question

2 Answers 2

up vote 3 down vote accepted

A bash suggestion:

   for file in *.JPG; do newfile=`echo $file|sed 's/.JPG$/.jpg/'` ; mv -i "$file" "$newfile" ; done

It loops over all the files with a .JPG extension, and for each of them it uses sed to construct the new filename by turning a terminal .JPG into a terminal .jpg, and performs the mv. The -i is just in case you have a fred.JPG and a fred.jpg already. Don't forget to distinguish between single quotes and backticks, both of which are used, and aren't interchangeable.

share|improve this answer
2  
Or use the preferred $(). Also, variables that contain filenames should always be quoted in case there are spaces in the names. –  Dennis Williamson Nov 12 '10 at 15:15
    
Dennis is absolutely right, I should have thought of that, and have modified the above accordingly. On the other hand, filenames with spaces are an aberration and should be avoided anyway! (opinion! opinion!) –  MadHatter Nov 12 '10 at 16:26
    
Should I just run this from within the directory using Terminal? –  dannymcc Nov 12 '10 at 20:43
    
@dannymcc: Yes. MadHatter: Photographs and music are two of the file types that one should expect to spaces in their names. –  Dennis Williamson Nov 12 '10 at 22:33
    
Worked a treat, thanks! –  dannymcc Nov 12 '10 at 23:07

If you have the utility called rename installed (it's a Perl script) you can do:

rename 'y/A-Z/a-z/' *
share|improve this answer

Your Answer

 
discard

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.