Q:

Mass rename of files in linux

I have files i linux that are in format :
img_1234563_@_12345.XX-FFF-123334-35370-122232-12342.gif
img_1234fdfd3_fd12345.XX-FdFF-1233343-35370-145232-d12342.gif

that I would like to rename to the something like
img_1234fdfd3_fd12345.jpg

So cut all after first dot and put jpg at the end
I have tried to use for and  rename with pattern like img_/\S[//^.]+ 
but without much success :(

A:

You can use the String split to divide your file names. When having a variable s you can retain the shortest match of a pattern from the beginning using ${MYVAR/%pattern}.
I do not know if you are processing all the entries on a directory so I suppose you have a variable files containing all the file names you need to rename. Otherwise you just need to change the loop bound to fit your list of files.
#!/bin/bash

files="img_1234563_@_12345.XX-FFF-123334-35370-122232-12342.gif img_1234fdfd3_fd12345.XX-FdFF-1233343-35370-145232-d12342.gif"

for file in $files; do
        name="${file/%.*}"
        fullName="${name}.jpg"                                                                                                                                                                                                                                             
        mv "$file" "$fullName"
done 

