⚡ Productivity

How to Replace Spaces with Dashes in File Names on Mac

File names with spaces cause problems on the web, in code, and when sharing. Here is how to replace spaces with dashes or underscores across hundreds of files on Mac.

ZeroApps TeamAugust 12, 20265 min read

File names with spaces are perfectly fine in Finder, but they cause headaches everywhere else. On the web, a space in a URL becomes %20. In a terminal, you need to quote every path with spaces. When uploading to a server, web tools, or a content management system, spaces often get mangled or rejected entirely.

The fix is simple: replace spaces with dashes (-) or underscores (_) in the file name. This guide shows every way to do that on a Mac — from a single file to hundreds at once.

Rename One File at Once in Finder

If you only need to fix one or two files:

  1. Click the filename once to select the file.
  2. Press Return (or click the filename again slowly) to enter rename mode.
  3. Edit the name manually, replacing spaces with dashes.
  4. Press Return to confirm.

This works fine for a handful of files. For anything larger, keep reading.

Replace Spaces in Multiple Files Using Finder

macOS Finder's built-in batch rename handles space replacement directly:

  1. Select all the files you want to rename (Command + A selects all in a folder).
  2. Right-click any selected file and choose Rename X Items…
  3. In the dialog, choose Replace Text from the dropdown.
  4. In Find, type a single space character.
  5. In Replace With, type - (a dash) or _ (an underscore).
  6. Click Rename.

Finder processes every selected file and replaces spaces in the filename. Note that Finder replaces only the first space unless you use a more advanced method — if a filename contains multiple spaces (like My Holiday Photos 2024.jpg), you may need to run the rename more than once.

Tip: Finder's batch rename has no undo. Double-check your selection before clicking Rename.

Replace Spaces Using Terminal

For developers or anyone comfortable with the command line, a shell loop handles every space in one pass:

# Replace all spaces with dashes in the current folder
for f in *; do mv "$f" "${f// /-}"; done
# Replace spaces with underscores instead
for f in *; do mv "$f" "${f// /_}"; done

These loops work on all files in the current directory. To include files in subfolders, combine with find:

find . -name "* *" -exec bash -c 'mv "$1" "${1// /-}"' _ {} \;

Terminal is precise and fast for those who know it. For others, it is easy to make a small error that renames files unexpectedly.

Replace Spaces in Bulk with RenameZero

RenameZero handles space replacement across hundreds of files with a live preview before anything is changed:

  1. Open RenameZero and drag in your files or a folder.
  2. Select the Replace Text operation.
  3. In the Find field, type a space character.
  4. In the Replace field, type - or _.
  5. The preview column immediately shows the new filename for every file.
  6. Click Rename to apply.

If you also want to convert the filename to lowercase at the same time (a common web convention: my-holiday-photos-2024.jpg), you can combine Replace Text with the Change Case → lowercase operation in the same session.

The free tier of RenameZero supports Replace Text for up to 20 files. For larger batches — or to add undo, sequential numbering, or folder-level processing — a Pro license removes all limits.

What About Files With Multiple Consecutive Spaces?

Files sometimes end up with two or three spaces in a row, resulting in My--File.jpg after a simple replacement. To collapse multiple spaces into one before replacing:

In Terminal:

for f in *; do mv "$f" "$(echo "$f" | tr -s ' ' '-')"; done

In RenameZero: Run Replace Text twice — first replace two spaces with one space, then replace the remaining single space with a dash. Or use the Remove Text operation to strip extra spaces before applying the replacement.

Web File Naming Best Practices

When naming files you will use on the web or in code:

  • Use lowercase letters (my-file.jpg not My-File.jpg)
  • Use dashes over underscores for URL readability (Google treats dashes as word separators)
  • Avoid special characters: & # @ ! ( ) [ ] { } , ; : ' " / | * ? < >
  • Keep names short and descriptive

RenameZero can handle the full cleanup — replace spaces, change to lowercase, remove special characters — in one batch operation with a live preview.

FAQ

Does replacing spaces break my files? No. Renaming changes only the filename. The file contents are untouched.

Can I undo a batch space replacement in Finder? No — Finder's batch rename has no undo. If you make a mistake, you need to rename manually. RenameZero includes one-click undo (Pro) that restores all original filenames instantly.

Should I use dashes or underscores? For files used on the web (images, documents, code assets), dashes are generally preferred — search engines and URL parsers treat them as word separators. For code variables or files used in scripts, underscores may be more conventional.

Will this work on folders, not just files? Yes. Both Finder's batch rename and RenameZero can rename folders using the same steps.

Summary

Replacing spaces in file names on Mac takes seconds once you know the right tool. For one or two files, edit directly in Finder. For small batches, Finder's built-in batch rename works well. For larger batches with a safety preview and undo, RenameZero is the most reliable option.

Also see: How to remove special characters from file names and how to rename hundreds of files at once on Mac.

#rename files#spaces#dashes#batch rename#mac#renamezero

Featured app

RenameZero

View app

Continue reading

Looking for the right macOS tool?

ZeroApps utilities handle PDFs, images, privacy and more — all locally on your Mac.

Browse all apps