Linux: Rename extension of multiple file in a folder

I sometimes need to change extension of multiple files in a folder. So I wrote a bash script to do this easily. And I am sharing it from here. It’s simple to use it. For example; you have a folder named folder1 and it has files with the extension ‘.abc‘ in it. And you want to change ‘.abc‘ extension with ‘.txt‘. The only thing you must do is run the commandline bottom;

bash rename_extension.sh abc txt /dir1/dir2/folder1

You can download script from here.

#!/bin/bash

##################################################
#  C*          rename_extension.sh           C*  #
#  C*       written by Nuh Azginoglu         C*  #
#  C*           February 09, 2016            C*  #
#  C*                                        C*  #
#  C*  renames files with new extension.     C*  #
##################################################

echo "usage: bash rename_extension.sh old_extension new_extension directory"


old_extension=$1
new_extension=$2
directory=$3

for file in $directory*.$old_extension; do
    mv "$file" "$directory`basename $file .$old_extension`.$new_extension"
done

Yazının Türkçe versiyonuna buradan erişebilirsiniz.

 

(30.04.2019 tarihinden itibaren toplam 1 kez, bugün 1 kez ziyaret edildi. )
Yorum yaz

0 Yorumlar.

Yorum Yap


Not - Bunları KullanabilirsinizHTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>