Debian Admin - Your way to Debian World

August 12, 2007

Rename multiple files to another extension in Linux

by @ 5:06 pm. Filed under General

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...

5 Responses to “Rename multiple files to another extension in Linux”

  1. jds Says:

    ich mag prename lieber …

  2. James Says:

    You can also use the ‘rename’ command included with most debian installs. It’s a little more intuitive, imho.

    $ rename
    Usage: rename [-v] [-n] [-f] perlexpr [filenames]

    $ rename ’s/\.php5/.php/’ *.php5

  3. Christian Geisert Says:

    And I’m using ‘mmv’ ;-)

  4. hron84 Says:

    And this can be usede too:

    #!/bin/bash
    for x in *.php5; do n=${x/.php5/.php}; mv $x $n; done

    And it’s can be used in other dir than ‘.’

  5. Zodak Says:

    The same can be done using the parameter expansion feature of the bash shell.

    for a in *php5 ; do mv $a ${a%%5} ; done

Leave a Reply

Subscribe RSS Feed

subscribe to the Debian Admin RSS feed

Internal links:

Sponsors:



Categories:

Support Debian Admin

Amount $:
Website(Optional):

Sponsors:

Archives:

WidgetBucks - Trend Watch - WidgetBucks.com

Related Links:


WidgetBucks - Trend Watch - WidgetBucks.com

Favourite Sites:

Wordpress Collection
Windows Reference
Ubuntu Geek
DebianHelp
All About Debian Tutorials
Power Electrical
Check Your IP Here
Debian,Ubuntu News
DebCentral
Tuxmachines
Capnkirby
Libervis
Nuxifield
Linux Horizon
Linux Appfinder
Debuntu
GNU/Linux For Everyone
Free Penguin
DebianAdmin is not related to the Debian Project.
This site is copyright © 2006,2007 Debian Admin
All Trademarks are the property of their respective owners.
The contents of this website may not be mirrored or archived without the express written permission of DebianAdmin Site Owner.

DISCLAIMER: All the information, troubleshooting methods, utilities offered in this website is provided AS-IS, without any warranties. Though I strive for perfection, and always test the validity and effectiveness of the troubleshooting content in various systems, I assume no responsibility for your use of these Fixes, Utilities and other troubleshooting advice. The author will not be liable for any special, incidental, consequential or indirect damages due to loss of data or any other reason. All use is completely at your own risk. Changes to the existing content and new additions are made to this website periodically, without notification.
Rodney's Kontera DynamiContext Plugin plugged in.