- Debian Admin - http://www.debianadmin.com -

Rename multiple files to another extension in Linux

Posted By Admin On 12th August 2007 @ 17:06 In General | 5 Comments

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Let us say that you want to rename all of your “.php5″ files to “.php” files. You can use for loop.


for old in *.php5; do cp $old `basename $old .php5`.php; done

Thats all there is to it. Let us say you need to rename index.php5 to index.php. The way above snippet works is that it loops through current directory and finds all the files with extension “.php5″ and processes ‘one by one. In our index.php5 file example, it finds index.php5 file, does a cp index.php5 `basename index.php5 .php5`.php <- basename returns “index” so you add .php to it and now you are left with index.php. Of course you can do mv command if you want to just move the file to new name.

Tag:

You may also be interested in...


Article printed from Debian Admin: http://www.debianadmin.com

URL to article: http://www.debianadmin.com/rename-multiple-files-to-another-extension-in-linux.html

Click here to print.