Renaming Files In Linux

In a previous post, I wrote about converting strings from camelCase to undescore delimited format.

In this post, we’ll do the same but for file names. We’ll use the command line program “rename” for this purpose.
Here we go:

1. Convert all file names in current directory which are of the form “myFileName” or “MyFileName” into the form of “my_file_name”:

1
rename 's/(.)([A-Z])/$1_\l$2/g' * && rename 's/([A-Z])/\l$1/g' *

2. Convert all file names in current directory which are of the form “my_file_name” into the form “myFileName”:

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

3. Convert all file names in current directory which are of the form “my_file_name” into the form “MyFileName”:

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

Enjoy ;)

If you enjoyed this post, make sure you subscribe to my RSS feed!

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Related posts:

  1. Fetch Links From Twitter Into Your RSS Reader
  2. Vim Tip – Convert Code To HTML
  3. Strip the File Name Suffix off a Bash Variable

Tags: ,

Saturday, May 30th, 2009 Bash

Trackbacks/Pingbacks

Leave a Reply

my email
my photo
Hi,
My name is Amir Watad. I have a BSc. in biomedical engineering from The Biomedical Engineering school , Technion , Israel, and a BSc. in electrical engineering from The Electrical Engineering school , Technion , Israel.
I'm a Verification Engineer in Mellanox Technologies Ltd.
I love Linux, the Command Line and the OpenSource Community.
I used to write Poems (Arabic) when I was able to find time for this.
May 2009
S M T W T F S
« Mar   Jun »
 12
3456789
10111213141516
17181920212223
24252627282930
31  
SEO Powered by Platinum SEO from Techblissonline

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.