Search code examples
bashperlfile-rename

Getting random number sequence on a filename using rename on Linux


So I'm trying to mass rename folder full of JPG-files using the 'rename'-tool

End result should be looking something like this

745I-24814
745I-(five random numbers)

I need something that gives me those five random numbers, the rest works fine

rename -n  's/\w+/745I\- [stuff] /' *.jpg

Most things just, like those two, act as strings instead of code or give gibberish

'int(rand(1000))+1000'
$(( ( RANDOM % 1000) + 1000))

Solution

  • Your version of rename uses a Perl substitution, to execute code in the replacement, you need /e:

    s/\w+/10000 + int rand 90000/e