Converting filenames to Title Case in Linux

Here's a simple bash one-liner to convert mixed-case filenames into Title Case:

rename 's/(\S+)/\u\L$1/g' *

This forces the file extension to lower-case as well.

Use rename -n to test the command without changing anything on the filesystem.

(Adapted from this PerlMonks FAQ.)


I have a bunch of inconsistently named files like:

hey jude.mp3
The lOng and wiNDing Road.mp3

I want them to appear as:

Here Comes The Sun.mp3
Hey Jude.mp3
The Long And Winding Road.mp3

Two Line Approach

First, rename all files to lower-case:

rename 'y/A-Z/a-z/' *

Second, make the first letter of each word Upper Case:

rename 's/(^|[\s_-])([a-z])/$1\u$2/g' *

4 thoughts on “Converting filenames to Title Case in Linux

  1. You didn't remove the spaces! What sort of monster are you!? 😉

    I like the rename command though. Years of poking around *nix and I didn't recall ever encountering it. I would have used to mv and an argument involving tr to convert lowercase.

    $ echo "The lOng and wiNDing Road.mp3" | tr [:upper:] [:lower:]
    the long and winding road.mp3

Leave a Reply

Your email address will not be published. Required fields are marked *