I have folder with about 1200 files that I need to rename. Theit file extension is .jpg, .gif, and .png for the most part. Here are some examples:    Awesome\ FB\ \ (462).jpg       Bonus\ FB\ Cover\ Pics\ (80).jpg    Awesome\ FB\ \ (463).jpg       Bonus\ FB\ Cover\ Pics\ (81).jpg    Awesome\ FB\ \ (464).jpg       Bonus\ FB\ Cover\ Pics\ (82).jpg    Awesome\ FB\ \ (465).jpg       Bonus\ FB\ Cover\ Pics\ (83).jpgI tried:    rename 's/\.{???} $/-img4sm.{???}/' ./*.{???}I also tried this but just placing a .jpg or .gif instead of {???}, and replacing the {} with []. I also tried:    find . -type f -iname '*.???' -exec rename 's/\.{???} $/-img4sm.{???}/' ./*.{} +I've managed to use this command without error messages in CloudLinux (CentOS), but no file names changed. Please help me.  Thank you! 
Rename all files in directory while preserving any file extension
find;rename
Here is a solution using php based on this answer.Create a file eg myrename.php with the following contents:<?php$test = 1;if(!chdir('/tmp/mydir')) echo failed chdir\n;else if ($handle = opendir('.')) {    while (false !== ($fileName = readdir($handle))) {        $newName = preg_replace(/\.(jpg|gif|png)$/i,-img4sm.\\1,$fileName);        if($newName!=$fileName){            if($test){                echo $fileName -> $newName\n;            }else{                if(!rename($fileName, $newName))echo failed $fileName -> $newName\n;            }        }    }    closedir($handle);}?>replace /tmp/mydir by the path of your directory. Run the script withphp myrename.phpand it will print out the old filename and new filename for each matched file.If this is ok, change $test = 1; to $test = 0; and run it for real.Remember to backup the files somewhere first in case of problems.