Rename multiple files to another extension in Linux

 
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.

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

Нема коментара:

Постави коментар