Shell Programming Blog Shell Programming Blog

Friday 12 October 2012

Linux Bash Scripting: How to rename multiple files in a single go

Unknown | 10:39 |


Bash Linux Unix shell scripting

You might come across a situation where you need to rename lot of files with similar file names either by editing the file name or by truncating the last part of the file name. There are two ways by which you can accomplish the task.

Method 1:

You can use the "rename" command to rename multiple files in a single go.

Syntax:

rename from to file...

- from is the word that you want to change in the file name
- to is the word that you want to replace with
- file is the file that want to rename ( you can use regular expression to select multiple files here

Example:

rename .html .htm *.html

This will change the extension of all the html files present in the current directory. The from and to keywords need not be the last characters of the file names. It can be anywhere in the file names

Method 2:

This method utilizes the "for" loop and "mv" command to rename all the files in a single go.




The above script will change all the html file name from *.html to *.htm

1 comment:

Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.

Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
3. Please do not spam, spam comments will be deleted immediately upon my review.

Regards,
Mohamed Abubakar Sittik A

 

Shell Programming Copyright © 2012 Shell Programming theme is Designed by Abusittik, Shell Programming