Linux

Remove Double Extensions in Linux

 

Following script will help you to remove double extensions which can be added by some programs or by user mistakes and need to be corrected in bulk.

Here is the solution, You have to perform this in the current working directory (non-recursively).

vim fix_extension.sh

Content of fix_extension.sh


#!/bin/bash
echo "Existing Extension" $1
echo "Converted Extension" $2
for file in *$1
do
mv "${file}" "${file%$2}"
echo " -- Fixing ${file%.$2}"
done

chmod +x  fix_extension.sh

Now run this script as:

sh fix_extension.sh <double_wrong_extension> <correct_extension>

for example,

For double extension .jpg.jpg do this:

sh fix_extension.sh .jpg.jpg .jpg

Voila!!

Download this script : fix_extension.sh

You Might Also Like