I have a series of files. I need to apply a series of file names.


  • 001.jpg -> apple.jpg
  • 002.jpg -> banana.jpg
  • 003.jpg -> orange.jpg
  • etc.

I will have to repeat this for each of 16 folders with 292 files per folder. The files will always be in the correct numbered order, but not always the same names (the first series will be 001.jpg-292.jpg, then 293.jpg-584.jpg, etc.). The supplied names will be the same for the files in all 16 folders.

I see that this is possible (and quite easy!) with apps like A Better Finder Rename, but I'm not keen on spending the $20 on all those features just to do one thing which I don't expect I'll ever have to do again :D

So, is there some kind of free option, like Automator, an Applescript, or a shell script?

I've found several shell scripts that repeat the same action for all files, but I don't know enough to edit them and supply a new name for each rename operation. :(

Even if I have to make a script that's 292+ lines long, hard-coding the name list into it, that would be easier than manually renaming them all in finder one-by-one!

1 Answer 1


For example save this file as filenames.txt:


Then open Terminal and run:

a=($(<filenames.txt));for d in *;do i=0;for f in $d/*;do echo mv $f $d/${a[i++]}.jpg;done;done

Remove echo if the output looks right.

If the file names contain spaces, add IFS=$'\n'; to the start and add double quotes around the variables.

  • Thanks! This almost works. The only problem is, it uses the first name in filenames.txt for all 292 files! …any ideas?
    – iynque
    Dec 20, 2013 at 1:34
  • Did you change the working directory to the folder that contains the other folders? Or if you need to run the script in each folder separately, remove the for d in *; part and ;done from the end.
    – Lri
    Dec 22, 2013 at 12:48
  • I did edit the command and ended up with output like "mv 001.jpg apple.jpg; mv 002.jpg apple.jpg; mv 003.jpg apple.jpg…" etc.
    – iynque
    Dec 23, 2013 at 15:08

You must log in to answer this question.

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