Howto: Linux Rename Multiple Files At a Shell Prompt

Monday, November 14, 2011

How do I rename multiple files at a shell prompt under Linux or UNIX operating systems?


Believe it or not, there is a 'rename' command (you don't always have to use mv!!)

rename "regex-rule" files 
 

Rename command syntax

rename oldname newname *.files
For example rename all *.foo file as *.bar, enter:
$ rename .foo .bar *.foo

Examples: Linux Rename Multiple Files

The regex command is as follows
<start>/<string to get replaced>/<string to replace it with>/g <replace all vars>

So removing all blank space with rename command:
$ rename "s/ *//g" *.mp3

To remove .jpg file extension, you write command as follows:

$ rename 's/\.jpg$//' *.jpg

To convert all uppercase filenames to lowercase:

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

To Remove a String from a filename:

$ rename 's/mystring//g' *



Read the man page of rename command for more information:
man rename