Guides · files
How to rename many files at once
By Lalla Asmaa Alaoui, founder of Mel · Updated
Make a list of the proposed new names first, check it, and only then apply all the renames in one go. On Mac and Linux a short for loop with mv -n does the job; on Windows, PowerShell's Rename-Item with -WhatIf lets you preview before anything changes.
The preview step is what keeps a bulk rename safe. A single typo in a pattern can rename hundreds of files the wrong way, and two files can end up with the same name. Work on a copy of the folder the first time.
Before you start
- Back up or copy the folder. For photos or documents you care about, copy the folder first. For a project in git, commit first so
git statusshows every rename afterwards.
- Go to the folder.
cd ~/Pictures/holiday-2026Mac and Linux
- Preview the renames. This example changes
.jpegto.jpg. Theechoprints each command instead of running it:
for f in *.jpeg; do
echo mv -n -- "$f" "${f%.jpeg}.jpg"
done${f%.jpeg} is the name without .jpeg. Quotes keep names with spaces intact.
- Read the list. Check a few lines at the top and bottom. Are the new names right? Are there any duplicates?
- Run it for real. Remove
echo:
for f in *.jpeg; do
mv -n -- "$f" "${f%.jpeg}.jpg"
done-n means "do not overwrite": if the new name already exists, that file is skipped instead of replaced. -- stops a name that starts with - from being read as an option.
- More patterns. - Add a prefix:
mv -n -- "$f" "trip-$f"- Replace spaces with hyphens:mv -n -- "$f" "${f// /-}"(bash and zsh) - Number files in order:
i=1
for f in *.jpg; do
printf -v new "photo-%03d.jpg" "$i"
echo mv -n -- "$f" "$new"
i=$((i+1))
doneprintf -v works in bash. In zsh, use new=$(printf "photo-%03d.jpg" "$i") instead. Remove echo once the preview looks right.
Many Linux systems also have a rename command, but there are two different tools with that name and different syntax. Check man rename before you use it.
Windows
- PowerShell, with a preview.
Get-ChildItem *.jpeg |
Rename-Item -NewName { $_.BaseName + ".jpg" } -WhatIf-WhatIf prints what would happen without renaming anything. When the list is right, run it again without -WhatIf. To replace spaces with hyphens:
Get-ChildItem -File |
Rename-Item -NewName { $_.Name -replace ' ', '-' } -WhatIfRename-Item stops with an error instead of overwriting a file that already exists.
- Command Prompt, for simple extension changes.
ren *.jpeg *.jpgren has no preview, so use it only for simple cases like this, and run dir *.jpeg first to see what will change.
Renaming files in a git project
Use git mv old-name new-name so git records the rename. For many files, the loop above works too; git usually detects renames on its own when you commit. Run git status to check.
Doing it with Mel
In Mel, you can run every command above at the prompt in your own shell, and each preview prints into a block you can scroll and filter before you run the real thing.
You can also describe the rename in plain English. Press ctrl+enter (cmd+enter on macOS) and write something like:
In this folder, rename every photo to YYYY-MM-DD-NNN.jpg using each
file's last-modified date. First show me a table of old name and new
name. Do not rename anything until I approve the list.The agent can work out the pattern, show you the proposed names and then run the renames. In Mel, renaming files runs as a command, so with approvals on, the rename shows on an approval card before it runs and you can deny it. If something looks wrong, say what to change and ask for a new list.
FAQ
How do I rename multiple files at once on a Mac? Use a for loop with mv -n in Terminal, as in step 5. Finder can also rename a selection: select the files, right-click and choose Rename.
How do I bulk rename files in Windows? Use PowerShell's Rename-Item with -WhatIf to preview, then run it again without -WhatIf. For simple extension changes, ren *.old *.new works in Command Prompt.
How do I change the extension of many files? On Mac and Linux, loop with mv -n -- "$f" "${f%.old}.new". In PowerShell, use Rename-Item -NewName { $_.BaseName + ".new" }.
How do I avoid overwriting files when renaming? Use mv -n on Mac and Linux. PowerShell's Rename-Item will not overwrite an existing file. Always preview first.
Can I undo a bulk rename? Not with one command. That is why you preview and keep a copy. In a git project, git status and git restore can help you put things back.
Mel – the agentic terminal · openmel.dev. A multi-agent, multi-model AI terminal for Mac, Windows, Linux and VS Code. Free with your own API key.

Lalla is a hands-on tech founder, agentic infrastructure architect and the vision behind Mel.
Follow on LinkedIn