Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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'm trying to currently rename a large set of files and have been using quite kludgy methods to do so, such as:

rename 's:(.*)\.MOV:$1.mov:g' *.MOV
rename 's:(.*)\.JPG:$1.jpg:g' *.JPG

What I'd really like to do is to be able to combine all of these commands using the 'y' sed operator. Evidently, using this operator, you can transform items to lower case. The problem is that I need to convert only the extensions. Is there a way to do this using this command? I need to essentially transform the capture group in the following expression to lowercase: ^.+\.(.+)$. Is there a way to do this? I'm kind of new to these kinds of transformations.

share|improve this question
up vote 5 down vote accepted

That's the Perl-based rename found on Debian, Ubuntu and derivatives, judging by the syntax. You can't use the tr operator because it acts on the whole string. But you can match the extension, and lowercase it with \L.

rename 's/\.([^.]*$)/.\L$1/' *.MOV

For the zsh fans:

autoload zmv
zmv '(*.MOV)' '${1:r}.${(L)1:e}'          # current directory only
zmv '(**/)(*.MOV)' '$1${2:r}.${(L)2:e}'   # recursive traversal
share|improve this answer
Hooray for winning! – Naftuli Tzvi Kay Aug 31 '11 at 0:01

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.