Batch Rename Files with rename

By | 2011/04/24

How can I batch rename files in Linux?

There are tons of how-tos and guides on using sed, mv, and other commands to batch rename files. However, a very powerful tool available in Debian and Ubuntu Linux is simply rename.

The rename command can be used to mass / bulk rename files, file extensions, rename files to lowercase, or other various tidbits your command-fu can dream up with perl expressions.

Here is a simple guide to get you started. (Note these work with Debian / Ubuntu perl version of rename. YMMV if you are using another distro or OS!)

Rename a directory of .jpeg files to .jpg:

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

From the man page, here is a way to rename a directory of files to all lowercase:

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

This replaces spaces in filenames with underscores:

$ rename 'y/ /_/' *

This for example will replace the letters abcd with wxyz:

$ rename 's/abcd/wxyz/' *
abcd_1-2011.txt -> wxyz_1-2011.txt

Rename those DSCN6249.JPG photos off your camera to something more desirable:

$ rename 's/DSCN/party/' *


Fedora users, try something like this:

$ rename abcd wxyz *


abcd_1-2011.txt -> wxyz_1-2011.txt