rename extension of multiple files in linux
My requirement was to rename the extension of multiple files in a directory.
My Directory was having some 20 image files with extension ".png" .
I want to rename the extension ".png" to ".bmp" in the directory.
I tried this script and it was working fine.
# List files ending with ".png"
for i in `ls *.png`;
do
# Get the File Name without Extension
d=`echo $i|tr -d ".png"`
#Append .bmp to the File Name and rename the file
mv $i "$d.bmp";
done
I run this in CentOS.
One thing is the use of tr command in the script helps to get the file name by cutting the extension.
tr - Translate or delete characters
-d
option implies to delete characters with ".png" in the word
My requirement was to rename the extension of multiple files in a directory.
My Directory was having some 20 image files with extension ".png" .
I want to rename the extension ".png" to ".bmp" in the directory.
I tried this script and it was working fine.
# List files ending with ".png"
for i in `ls *.png`;
do
# Get the File Name without Extension
d=`echo $i|tr -d ".png"`
#Append .bmp to the File Name and rename the file
mv $i "$d.bmp";
done
I run this in CentOS.
One thing is the use of tr command in the script helps to get the file name by cutting the extension.
tr - Translate or delete characters
-d
option implies to delete characters with ".png" in the word
No comments:
Post a Comment