Shell script: Rename extensions of multiple files.

Shell provides easy way of renaming multiple files.

Eg: your directory has ’01 – Song1.mp3′, ’02 – Song2.mp3′, ’03 – Song3.mp3′ and you want to rename them to .txt. use the following commane.

$rename mp3 txt *.mp3

The above command renames .mp3 files to .txt.

An alternate script solution from here


#!/bin/sh
ls *.mp3|while read file
do
target=`echo $file|cut -d . -f 1`
#mv "$file" "$target.txt"
echo "$target.txt"
done

First test the above script by seeing the echo "$target.txt" output then uncomment the line above it and comment this line.

About Ajo Paul

A Monk who's yet buy his Ferrari!
This entry was posted in linux, script and tagged , . Bookmark the permalink.

One Response to Shell script: Rename extensions of multiple files.

  1. Great review! You actually covered some curious things on your blog. I came across it by using Bing and I’ve got to admit that I already subscribed to the RSS feed, it’s very great :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre user="" computer="" escaped="">