Convert all file extensions to lower-case

Viewed 53013

I'm trying to lower-case all my extensions regardless of what it is. So far, from what I've seen, you have to specify what file extensions you want to convert to lower-case. However, I just want to lower-case everything after the first last dot . in the name.

How can I do that in bash?

11 Answers

I was looking for a simple way to do this (without having to think about it) but I finally ended up thinking it through and came up with this (admittedly, way after the original post)

find . -name \\*.JPG -print -exec rename s/.JPG/.jpg/ {} \\;

I ran it on about 60 thousand files and it worked fine but, of course, you can use the -n option to 'rename' if you want to test it out first.

So, these solutions that look like line noise are nice and all, but this is easy to do from the python REPL (I know the OP asked for bash, but python is installed on a lot of systems that have bash these days...):

import os
files = os.listdir('.')
for f in files:
    path, ext = os.path.splitext(f)
    if ext.isupper():
        os.rename(f, path + ext.lower())
Related