Skip to content
Home » How to Rename Multiple Files at Once on a Mac

How to Rename Multiple Files at Once on a Mac

The Finder has had a batch rename tool built in for years, and a lot of people still rename files one at a time because it is hidden behind a menu item that only appears when more than one file is selected. That covers most cases with no typing at all. For the ones it does not — renaming by pattern, or reaching into subfolders — the shell that ships with every Mac has a tool that does it in one line, with a dry run so you can check before anything moves.

Rename them in the Finder

  1. Select the files. Click the first, then Shift-click the last for a run of them, or Command-click to pick them out individually.
  2. Right-click the selection and choose Rename … Items… — the wording includes the count, so with four files selected it reads Rename 4 Items….
  3. Pick a mode from the pop-up menu at the top left of the sheet, fill in the fields, and check the preview line at the bottom.
  4. Click Rename.

The menu item is worth pointing out because it changes with the selection: one file gives you Rename and the ordinary inline edit, and only two or more produce the batch sheet. People who have only ever selected one file at a time have never seen it exist.

It is undoable. Command-Z immediately afterwards puts every name back in one step, which is the safety net that makes it worth trying on real files rather than a test copy.

The three rename modes

The pop-up offers exactly three, and knowing which one you want is most of the job:

  • Replace Text — find a string in the existing names and swap it for another. This is the one for stripping a prefix a camera added, or fixing a misspelling repeated across a folder. Leave the replacement empty to delete the text outright.
  • Add Text — put something before or after the existing name, keeping it otherwise intact. Useful for tagging a batch with a project name.
  • Format — discard the old names and build new ones from a base name plus a counter, an index, or a date. This is the mode for turning a folder of camera files into Holiday 1, Holiday 2, and so on.

Two limits to know before you rely on it. Format numbers files in the order they are currently sorted in the window, so sort the way you want them numbered before opening the sheet — by date if that is the sequence you mean, not by name. And the whole tool works on the selection only: it will not descend into subfolders, so a folder of folders needs the Terminal.

One line in the Terminal: zmv

zsh is the default shell on macOS, and it comes with a batch renamer most people never switch on. Load it once per session:

autoload -U zmv

Then patterns work like a rename-shaped version of globbing: parentheses capture, and $1, $2 and so on refer back to what they captured. The -n flag makes it a dry run, printing what it would do without touching anything:

$ zmv -n 'IMG_(*).jpg' 'vacation-$1.jpg'
mv -- IMG_001.jpg vacation-001.jpg
mv -- IMG_002.jpg vacation-002.jpg
mv -- IMG_003.jpg vacation-003.jpg

That output is the whole argument for using this over a hand-written loop. You see every rename before it happens, in the exact form it will be carried out; drop the -n and the same three operations run for real.

Spaces, which are what usually breaks shell renaming, need no special handling — each captured group is quoted for you:

$ zmv '(*) (*) (*).png' '$1-$2-$3.png'
$ ls
holiday-photo-1.png

Use single quotes around both patterns. Double quotes let the shell expand $1 before zmv ever sees it, which is the mistake that makes every file collapse onto the same name.

And for the job the Finder sheet cannot do at all — reaching into subfolders — **/ matches any depth, and capturing it puts each file back where it came from:

$ zmv -n '(**/)(*).jpeg' '$1$2.jpg'
mv -- a/b/two.jpeg a/b/two.jpg
mv -- a/one.jpeg a/one.jpg
mv -- top.jpeg top.jpg

Three files at three different depths, each renamed in place, from one line.

The loop, when you want plain shell

If you would rather not rely on a zsh feature — a script that has to run under bash, say — the portable version is a loop with parameter expansion:

for f in *.jpeg; do mv "$f" "${f%.jpeg}.jpg"; done

${f%.jpeg} strips that suffix from the end of the name; ${f#prefix} does the same from the front. The quotes around both arguments to mv are not optional — without them a single filename containing a space becomes two arguments and mv either errors or, worse, moves the wrong thing.

There is no dry run here, so build one: replace mv with echo mv, read the output, then take the echo back off. That habit costs two seconds and has saved more folders than any undo.

One macOS-specific trap applies to both approaches. The default filesystem is case-insensitive but case-preserving, which has a consequence worth seeing rather than reading about:

$ touch report.txt
$ touch Report.txt
$ ls
report.txt

One file, still under its original spelling. The second command did not create anything — to the filesystem those are the same name. Changing case on its own is fine, mv photo.jpg Photo.jpg does exactly what it looks like, but a batch rename whose output collides with an existing file that differs only in capitalisation will quietly replace it rather than stopping. That is one more reason to run zmv -n, or echo mv, and read the list first.

Why the rename command is missing

Most instructions written for Linux reach for a command called rename. macOS does not have it:

$ ls /usr/bin/rename
ls: /usr/bin/rename: No such file or directory

This is the same situation as tree and wget — a tool that is standard on Linux distributions and simply not part of macOS. It is worth knowing that rename is not even one program on Linux: some distributions ship a Perl version taking regular expressions, others a util-linux version with completely different arguments, so a command copied from a forum post may not have worked on the poster’s machine either. zmv covers the same ground and is already installed.

Quick reference

SituationWhat to use
A folder of files, no pattern neededFinder: select, right-click, Rename … Items…
Strip or swap text in the namesFinder: Replace Text
Number a sequenceFinder: Format, after sorting the window
Rename by patternautoload -U zmv, then zmv -n 'pat' 'new'
Include subfolderszmv -n '(**/)(*).ext' '$1$2.new'
Portable shell scriptfor f in *.old; do mv "$f" "${f%.old}.new"; done
Undo what you just didFinder: Command-Z. Terminal: nothing — use -n first

The rule of thumb: if you can select the files in one window, the Finder sheet is faster and comes with an undo. If the rename follows a pattern, or crosses folders, zmv -n is one line and shows you the whole plan before it runs.

Leave a Reply

Your email address will not be published. Required fields are marked *