How to randomly rename files in bulk using Terminal in MacOS ?


Lemme guess, you want to bulk rename hundreds of photos in a folder, and looking for ways to batch rename files to random characters.

One way is to use an application like Renamer, but then again it won’t do much in a trial version.

While randomizing file names in a folder shouldn’t be that hard, the process is something that could take a long time, especially when you consider that many photo libraries have thousands of images. However, through the power of Terminal and the use of a for-loop, it is possible to randomly rename an entire folder of images with one fell swoop.

We will show you the easiest way to do it using mac’s inbuilt utility called Terminal, and a bit of coding.

In Terminal first type

Code: cd

(type one space after ‘cd’)

Then drag your directory to the Terminal window and press return. That will change to your image directory. Then paste

for i in *.jpg; do mv $i $RANDOM.jpg; done

The terminal will execute the script and depending on the number of images in your folder, you will see within some time, all your images will be renamed.

If you don’t do it exactly as per steps, you will get below error.

'-bash: syntax error near unexpected token `do'


Leave us comments if you have any issues and we will try to answer it.

About the Author

Gurminder is a political scientist and critical thinker based in Australia. He regularly blogs on constructive criticism.