Home > bash > Rename several files

Rename several files


I have 12 files named as Scan10032.JPG, Scan10033.JPG, …, Scan10043.JPG. From their names I want to remove the “Scan” prefix and I want the extension in lowercase.


There is a very handy script for this called rename which is part of the standard installation. It’s actually a Perl script, written by Larry Wall himself. So:

rename -n 's/Scan(.*)\.JPG/$1.jpg/' *.JPG

First use the -n switch which means “No Action: show what files would have been renamed.” It means the files are not renamed and you have the chance to verify everything. If it’s OK, just remove the -n switch.

For more info refer to the man page. If you want more fancy renames, check out this post of mine where I use a simple Python script for a similar problem.

Categories: bash Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: