Take the 2-minute tour ×

I have a bunch of photos with varying names.
I want to give each photo a random name(*), how do I do that?

(*)I'm going to put them on a digital photo-frame that can't shuffle

share|improve this question
Do you want a single solution that works for all of those platforms? Or a solution that works on any one? What script languages are you limited to or prefer? Are all the photos in one folder or multiple? –  EBGreen Jun 30 '11 at 20:43
@EBGreen - I have a solution that works wherever bash is available. I would also like one that works on windows. (and recommending cygwin is cheating) –  Nifle Jun 30 '11 at 20:51
Why not use the MD5 sum? –  AngelLeliel Jun 30 '11 at 22:54
While MD5 sums would make name collisions less likely, MD5 collisions are a known issue. mscs.dal.ca/~selinger/md5collision –  EBGreen Jul 1 '11 at 0:01
@Angel - Using the MD5 sum as a name would have worked pretty well for uniqueness. The extra time to calculate the sum on 4000+ photos would have been a boring wait. –  Nifle Jul 2 '11 at 10:52

4 Answers 4

up vote 4 down vote accepted

Assuming all the images are in a single folder, this would work in powershell:

Get-ChildItem *.jpg | ForEach-Object{Rename-Item $_ -NewName "$(Get-Random)-$($_.Name).jpg"}

It is possible that you would get potential name collisions, but Get-Random by default returns a 32 bit unsigned int from 0 to Int32.MaxValue (0 to 2147483647). You could certainly add another Get-Random in to reduce the likelihood of a collision just as in the Bash answer.

share|improve this answer

One way if you have a bash shell handy is to use the $RANDOM environment variable. It generates random values between 0 and 32767.

A simple for loop in bash works fine if you only have a few hundred files.

for i in *.jpg; do mv -i "$i" ${RANDOM}.jpg; done

Since I had about 4000 files to rename I soon got collisions that the -i flag to mv caught. Adding another $RANDOM took care of that.

for i in *.jpg; do mv -i "$i" ${RANDOM}${RANDOM}.jpg; done
share|improve this answer
Instead of "${RANDOM}${RANDOM}.jpg" you could also say "${RANDOM}-$i". This will avoid collisions and keep the old name information (as well as satisfy the random sort requirement). –  bitmask Jun 30 '11 at 21:17
Oooh...I like it....I'll tweak the PS solution to incorporate that. –  EBGreen Jun 30 '11 at 23:57
@bitmask - A good point. In this case the images didn't have any meaningful names and sometimes contained spaces so I was happy to get rid of them. –  Nifle Jul 1 '11 at 8:46

for f in *; do ext=$(echo "$f" | sed 's|\([^.]*\)||'); mv "$f" "$(uuidgen)$ext"; done

share|improve this answer
+1 for showing me that uuidgen exists. –  Nifle Jul 1 '11 at 8:48

Most batch file renamers can do this, here is one

Easy method would be to do a sequential numbering of the file, I am sure there other options with this software, use your imagination.

Here is the one I use for bulk renaming tasks

share|improve this answer

Your Answer


