This should work:
rename -n 's/^([0-9]+) (.*)\.jpg/$2 $1.jpg/' /path/to/files/*.jpg
Sample:
0324 [UNKNOWN] (Final Fantasy 9) headshot of Freya Crescent {sketch} (ORIGINAL).txt
0123 [UNKNOWN] (Final Fantasy 9) headshot of Freya Crescent {sketch} (ORIGINAL).txt
0124 [UNKNOWN] (Final Fantasy 9) headshot of Freya Crescent {sketch} (ORIGINAL).txt
Results:
rename(0123 [UNKNOWN] (Final Fantasy 9) headshot of Freya Crescent {sketch} (ORIGINAL).txt, [UNKNOWN] (Final Fantasy 9) headshot of Freya Crescent {sketch} (ORIGINAL) 0123.txt)
rename(0124 [UNKNOWN] (Final Fantasy 9) headshot of Freya Crescent {sketch} (ORIGINAL).txt, [UNKNOWN] (Final Fantasy 9) headshot of Freya Crescent {sketch} (ORIGINAL) 0124.txt)
rename(0324 [UNKNOWN] (Final Fantasy 9) headshot of Freya Crescent {sketch} (ORIGINAL).txt, [UNKNOWN] (Final Fantasy 9) headshot of Freya Crescent {sketch} (ORIGINAL) 0324.txt)
Note: Tested with .txt
files will also work on jpg filenames
Information:
([0-9]+)
: pick the numbers at the front.
(.*)
: pick every other thing till the file extension.
$2 $1.txt
: return the captured groups with the returned group for numbers
placed close to the file extension jpg
and add a space before the numbers.
-n
: run without changing filename so we see what files are changed and what the names are changed to, remove this to rename the files.