How to Find and Replace Text in Filenames on Mac

Find and replace is the most common batch rename operation. Replacing a word, removing a prefix, or swapping one string for another across hundreds of files saves hours of manual renaming. macOS provides three approaches: Finder for simple replacements, Terminal for scripted operations, and Batchio for visual workflows with live preview.

How Do You Find and Replace in Filenames Using Finder?

Finder finds and replaces text in filenames through the Replace Text rename mode. Select the target files, right click, choose Rename, switch to Replace Text, type the search string in Find and the replacement in Replace With. Finder performs a literal string replacement across every selected filename instantly.

Finder's Replace Text mode is the fastest way to perform a simple text substitution across multiple files on macOS. No additional software is needed. The operation supports replacing any text string with any other string, including replacing text with nothing (effectively deleting it). Type the text you want to remove in the Find field and leave the Replace With field empty to delete that text from every selected filename.

Finder performs case insensitive matching by default, so searching for "draft" matches "Draft", "DRAFT", and "draft" in filenames. The replacement preserves the original casing of the surrounding text. Finder replaces every occurrence of the search string in each filename, so be careful with short strings that might appear in unexpected positions. Preview the results in the rename dialog before clicking Rename.

How Do You Find and Replace in Filenames with Terminal?

Terminal finds and replaces text using a for loop with shell parameter expansion. The command for f in *; do mv "$f" "${f//oldtext/newtext}"; donereplaces every occurrence of "oldtext" with "newtext" in every filename. The double slash performs global replacement.

Shell parameter expansion provides a built in find and replace mechanism without requiring external tools. The syntax ${variable//pattern/replacement}replaces all occurrences of the pattern in the variable's value. A single slash replaces only the first occurrence. This approach handles most plain text substitution tasks efficiently and works on any macOS system without additional installations.

For regex powered find and replace, Terminal uses sed or the Perl rename command. The sed approach pipes each filename through the regex engine: for f in *; do mv "$f" "$(echo "$f" | sed 's/old/new/g')"; done. Terminal provides no preview, so always test with echo first. For regex recipes and advanced patterns, see the regex rename guide and the remove spaces guide.

How Does Batchio Handle Find and Replace?

Batchio's Find & Replace ruleprovides both plain text and regex modes. Type the search string in the Find field and the replacement in the Replace field. The live preview shows every match highlighted in the original filename and the resulting filename after replacement. Toggle regex mode for pattern matching.

Batchio's plain text mode performs exact string matching with an optional case sensitivity toggle. This mode is ideal for simple substitutions where the search string is always identical across filenames. Replace "draft" with "final", remove "copy" from duplicate filenames, or swap project codes. The live preview updates as you type, showing the original and new filename for every loaded file.

Toggle the regex switch when plain text matching is not sufficient. Regex mode accepts any regular expression pattern in the Find field and supports capture group references in the Replace field. This single toggle transforms the Find & Replace rule from a simple text substitution tool into a full regex engine. Stack multiple Find & Replace rules for multi step operations. The batch rename guide covers the complete Batchio workflow.

When Should You Use Regex Instead of Plain Text?

Plain text find and replace works when the search string is identical across all filenames. Regex is necessary when the text varies: different numbers, variable length strings, optional characters, or pattern based matches. Use plain text for exact strings and regex for anything that involves variability or positional matching.

Most find and replace operations are simple enough for plain text mode. Replacing a project name, removing a client prefix, or changing a word across filenames involves identical search strings. Plain text mode is faster to set up, easier to understand, and less error prone. It should be your default choice unless the task specifically requires pattern matching.

Regex becomes necessary when filenames contain variable content that follows a pattern. Removing numbers of varying length (1, 23, 456) requires \d+ because no single static string matches all variants. Extracting dates, reordering name components, and matching optional characters all require regex. If you find yourself running the same plain text replacement multiple times with different search strings, regex can usually accomplish the entire task in one pass. For regex patterns, see the regex cookbook.

What Are Common Find and Replace Scenarios?

Common scenarios include replacing spaces with underscores, removing "copy" or "(1)" from duplicated filenames, swapping project codes, changing date separators from slashes to hyphens, and removing file source prefixes like "IMG_" or "DSC_" from camera files.

Replacing spaces with underscores is one of the most frequent operations for web developers and anyone sharing files across operating systems. Spaces in filenames cause issues with URLs, command line tools, and some build systems. A simple find " " replace "_" operation solves this across an entire directory. The reverse operation (underscores to spaces) is equally common when preparing files for display.

Removing camera prefixes cleans up photo collections. Camera manufacturers use prefixes like IMG_, DSC_, DSCN_, P, and various other codes. A plain text find and replace removes these prefixes from every photo filename. Combine this with a numbering rule or date insertion rule to create meaningful filenames that replace the generic camera codes. For related cleanup operations, explore the prefix guide for removing camera prefixes from photo collections.

Frequently Asked Questions

Can Finder find and replace text in filenames?
Finder can find and replace text in filenames using its Replace Text batch rename mode. Select the files, right click, choose Rename, select Replace Text, type the text to find and the replacement text. Finder performs a literal string replacement on every selected filename. It does not support regex or pattern matching.
Is find and replace in filenames case sensitive?
Finder's find and replace is case insensitive by default. Terminal sed is case sensitive unless you add the I flag. Batchio provides a toggle to switch between case sensitive and case insensitive matching. Choose the mode that fits your filenames to avoid missed matches or false positives.
Can you find and replace in filenames without changing extensions?
Finder's Replace Text mode applies to the entire filename including the extension. If the search text appears in the extension, it will be replaced there too. Batchio separates the extension from the base filename, so find and replace operations only affect the name portion. The extension remains untouched unless you add a separate Extension Handling rule.
How do you undo a find and replace rename on Mac?
Finder supports Command Z to undo the most recent batch rename operation. Terminal provides no built in undo for rename commands. Batchio maintains a full undo history that lets you revert any rename operation, including find and replace changes, back to the original filenames.

Find and Replace with Live Preview

Download Batchio free on the Mac App Store. All 9 rule types included. Pro upgrade $4.99.

Coming Soon to the Mac App Store
Marcel Iseli
Marcel Iseli

Creator of Batchio · Indie App Developer

LinkedIn ↗

Marcel Iseli is an indie app developer and the creator of Batchio. He builds native macOS utilities focused on productivity and file management, with a focus on lightweight, subscription-free tools.