Ok, so I have a digital photo frame that I have, and view my photos from a USB. Everything works fine, however, there is no way to display the pictures randomly. So, I have to watch my pictures in order, which is fine but not really what I want.

I am wondering if there is a way to have my .jpg pictures, that I view to be batch renamed, but renamed randomly? Be it adding random characters to the start of the name or replacing the characters before .jpg

Thank you for your time and answers.

3 Answers 3


I suppose the following could work. Assuming the prefix of your filenames is "DSC" you can use the following command in the terminal (untested!)

cd /path/to/photos
rename 's/DSC/'$RANDOM'/' *.jpg

This uses the perl rename command to match regular expressions and replace them. In this case, we are substituting "DSC" with a random number in the filename for all .jpg files. Change the "DSC" to whatever your photos' prefix is.

another method (also untested) is with a bash script:

for f in *.jpg; do
  mv "$f" $RANDOM-"$f"
  • Great thanks I will try this tonight after work.
    – Dustin
    May 13, 2013 at 14:20
  • I renamed all the files from file-2.jpg to file.jpg, really helpful,
    – umesh
    Aug 21, 2016 at 0:39
  • Worked perfectly! Jun 1, 2021 at 22:03
for img in *.jpg; do
newname=$(head /dev/urandom | tr -dc a-z0-9 | head -c 8)
mv "$img" "$newname".jpg

This will shuffle all jpg files to random names.

  • Done. This will shuffle all jpg files to random names. The echo was what I've used to validate the script, it is now removed.
    – Mach Seven
    Dec 9, 2019 at 0:58

Following one line script works for file names with white chars.

for f in *.jpg; do mv -n "$f" "${f/*/$RANDOM.jpg}"; done
  • 1
    This is possibly dangerous and may cause loss of pictures.
    – Lekensteyn
    May 13, 2013 at 7:16
  • Indeed, previous version of script could overwrite existing file. May 13, 2013 at 7:19
  • The risk of collision is high. $RANDOM is between 0 and 32767. I would not recommend using this function. Or at least replace $RANDOM by $(head /dev/urandom | tr -dc a-z0-9 | head -c 8 ) Jul 2, 2022 at 12:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .