SOLVED: script to rename a file to a random alphanumeric

Forum rules
Before you post please read how to get help
Post Reply
danneauxs
Level 1
Level 1
Posts: 42
Joined: Thu Apr 10, 2014 5:37 pm

SOLVED: script to rename a file to a random alphanumeric

Post by danneauxs » Sat Jun 29, 2019 9:26 pm

Looking for a script to rename .rar file to a random alphanumeric with a unchanging prepended string.
Example:
a.rar
renamed to
hbox - eeYohv7kael2agheishe9ocuT4

right now I use pwgen to get the alphnum and manually rename.

I have used this previously
for fname in *.rar
do

mv $fname 'hbox - '${RANDOM}.rar
done
but I need more than just 4 numbers. I need a 26 character alphnum sequence.
I can't figure out how to use pwgen in this code.
I'm not married to pwgen either, it's just what I know.

thanks in advance
Last edited by danneauxs on Sat Jun 29, 2019 9:32 pm, edited 1 time in total.

danneauxs
Level 1
Level 1
Posts: 42
Joined: Thu Apr 10, 2014 5:37 pm

Re: script to rename a file to a random alphanumeric

Post by danneauxs » Sat Jun 29, 2019 9:32 pm

Well shoot found my answer, stupid typing mistake was killing me.

this works
for fname in *.rar
do

mv $fname 'hbox - '"$(pwgen 20 1).rar"
done
In case someone needs to know.

Post Reply

Return to “Scripts & Bash”