How To Rename Multiple Files Together in Linux Using 3 Methods

Renaming a single file is very simple task for Linux user. But renaming multiple files in group may not be a straight forward task. In this article, let us review 3 different methods to rename multiple files together.

Method 1. Use Rename Linux Command

Using rename command you can rename group of files. The syntax for renaming multiple files in group using rename command is given below.

Syntax: rename perlexpr [ files ]

To rename all the html files from html to htm extension in the current directory do the following.

rename s/.html/.htm/ *.html

Using the same concept, you an also rename all the *.txt files to *.bak files (or) all the *.bak files to *.txt files etc.,

Method 2. Use Linux Shell Script to Rename Multiple Files Together

You can write your own shell script to rename the files of specified pattern recursively as:

Method 3. Use Midnight Commander to Rename Multiple Files

Select the required files using regular expression. Press + which will ask the regex to select files. For example, giving *.psql will select all the files with psql extension.

Rename all the selected files using regex. Press F6 which will ask for the source and destination regex, doing so will change the file names. For this example, give *.psql in source and *.sql in destination which will rename all *.psql files to *.sql files.

There are lots of time when we require to swap files between two configuration files. Is there any single command which will swap two files instead of writing 3 commands like this: mv abc.txt tmp.txt; mv def.txt abc.txt; mv tmp.txt def.txt

Thanks for the info. mmv looks similar to rename. Is there anything special that mmv does which rename cannot do? (or) Is it pretty much the same?

@Nardi,

Your for-loop is similar to the method-2. Thanks for showing your detailed examples on how you do the move.

@Nabin,

I’m not sure whether there is a single command that will do the swap. I hope someone else can throw some ideas on your question. One thing that came to my mind is — Instead of doing multiple mv’s probably you can create a alias called mvswap which can have the multiple mv commands.

@Flynets,

Replacing space in a filename with underscore or hypen in a common requirement. Thanks for sharing your great example to solve that problem.

None of these examples appear to work in xandros linux (eeepc) except midnight commander which is so klunky I am frightened of using it.
Why is it SO difficult to rename multiple files in linux when it is so easy in DOS ?’
When i chose linux for my netbook I was swayed by the supposed easy availability of thousands of free programs. Well I can’t find a free program which will rename files – such a common requirement, and none of the command line solutions appear to work. (including chcase ) Does anyone know of one? Is it Xandros that is the problem?
There are dozens for Windoze….I did see in one forum where somebody actually suggested changing the file names manually one by one. Shome joke shurely?

to john.dennis@mailcatch.com:
Hi John. From your complaints we can hardly figure out how to help. It might be just a little misunderstanding or nonstandard behavior.
Could you please be more specific about what commands did you run and what output did you get? It would also be nice to know what shell are you using (type in “echo $SHELL”) just to make sure it unedrstands bash commands.
Yeah and how is this done in DOS actually?

About The Geek Stuff

My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about Ramesh Natarajan and the blog.

Contact Us

Email Me :
Use this Contact Form to get in touch me with your comments, questions or suggestions about this site. You can also simply drop me a line to say hello!.