Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 2 down vote accepted

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"
share|improve this answer
Great thanks I will try this tonight after work. – Dustin May 13 '13 at 14:20

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

for f in *.jpg; do mv -n "$f" "${f/*/$RANDOM.jpg}"; done
share|improve this answer
This is possibly dangerous and may cause loss of pictures. – Lekensteyn May 13 '13 at 7:16
Indeed, previous version of script could overwrite existing file. – Grzegorz Żur May 13 '13 at 7:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.