#!/bin/bash for filename in $(ls | grep -E "(^|_)[[:digit:]]{13}\.[[:alpha:]]{3,4}$") do filehash=$(md5sum "$filename" | sed -E "s/ \*.*$//") newfilename=$(echo $filename | sed -E "s/[[:digit:]]{13}/$filehash/") if mv -n $filename $newfilename then echo "$filename -> $newfilename" fi done