rename multiple file or extension in linux or unix


There might be many case where you want to rename multiple files or extensions. Like you may want to convert all php3 to php or html to htm.

On freebsd box you have got many option but not mv *.php3 *.php
The main reason for this not working is that the shells are not suppose to do so.

Also there are many ports available to do so.
But here I'll tell you about a simple csh shell script to do so.
Suppose you wan to rename all the file0.php3 file1.php3 .... filen.php3 to file0.php file1.php .... filen.php.

foreach file (*.php3)

mv -iv $file `basename $file php3`php

  • Remember that ` is backquote not '.
  • There is no space in php3`php.
  • RTFM for mv -iv.
  • RTFM for basename and foreach.
Happy mv.


Post a Comment

Comments are moderated. No spam please.

Popular posts from this blog

Adobe Stand Alone Flash Player for Linux

[Solved] invalid partition table on /dev/sda -- wrong signature 0.

Essential adb Command Examples